aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_communicator.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_communicator.c')
-rw-r--r--src/transport/test_communicator.c157
1 files changed, 139 insertions, 18 deletions
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
55static int ret; 55static int ret;
56 56
57// static char *addresses[NUM_PEERS]; 57static struct GNUNET_TIME_Absolute start_short;
58 58
59static struct GNUNET_TIME_Absolute start_long;
59 60
60#define PAYLOAD_SIZE 256 61static 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
64static 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
83static char short_payload[SHORT_MESSAGE_SIZE];
84
85static char long_payload[LONG_MESSAGE_SIZE];
86
87static uint32_t ack = 0;
88
89static int phase;
90
91static size_t long_received = 0;
92
93static size_t short_received = 0;
65 94
66static void 95static void
67communicator_available_cb (void *cls, 96communicator_available_cb (void *cls,
@@ -130,6 +159,73 @@ queue_create_reply_cb (void *cls,
130} 159}
131 160
132 161
162static void
163size_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
184static void
185long_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
203static void
204short_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
168incoming_message_cb (void *cls, 267incoming_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,
190static void 309static void
191run (void *cls) 310run (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 (