[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27198 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27198 - gnunet/src/transport |
Date: |
Fri, 17 May 2013 14:59:36 +0200 |
Author: wachs
Date: 2013-05-17 14:59:36 +0200 (Fri, 17 May 2013)
New Revision: 27198
Modified:
gnunet/src/transport/gnunet-service-transport_manipulation.c
gnunet/src/transport/test_transport_api_manipulation_cfg.c
gnunet/src/transport/test_transport_api_manipulation_cfg_peer2.conf
Log:
improved test
Modified: gnunet/src/transport/gnunet-service-transport_manipulation.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_manipulation.c
2013-05-17 11:37:35 UTC (rev 27197)
+++ gnunet/src/transport/gnunet-service-transport_manipulation.c
2013-05-17 12:59:36 UTC (rev 27198)
@@ -387,7 +387,6 @@
generic_send_delay_task =
GNUNET_SCHEDULER_add_delayed (delay, &send_delayed, next);
}
}
-
GNUNET_free (dqe);
}
@@ -454,7 +453,9 @@
memcpy (dqe->msg, msg, msg_size);
GNUNET_CONTAINER_DLL_insert_tail (generic_dqe_head,
generic_dqe_tail, dqe);
if (GNUNET_SCHEDULER_NO_TASK == generic_send_delay_task)
+ {
generic_send_delay_task =
GNUNET_SCHEDULER_add_delayed (delay, &send_delayed, dqe);
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delaying %u byte message to peer `%s'
with peer specific delay for %llu ms\n",
msg_size, GNUNET_i2s (target), (long
long unsigned int) delay.rel_value);
@@ -574,7 +575,7 @@
unsigned long long tmp;
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (GST_cfg,
- "transport", "MANIPULATE_DISTANCE_IN", &tmp))
+ "transport", "MANIPULATE_DISTANCE_IN", &tmp) && (tmp >
0))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Setting inbound
distance_in to %u\n",
(unsigned long long) tmp);
@@ -582,7 +583,7 @@
}
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (GST_cfg,
- "transport", "MANIPULATE_DISTANCE_OUT", &tmp))
+ "transport", "MANIPULATE_DISTANCE_OUT", &tmp) && (tmp >
0))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Setting outbound
distance_in to %u\n",
(unsigned long long) tmp);
@@ -590,7 +591,7 @@
}
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (GST_cfg,
- "transport", "MANIPULATE_DELAY_IN", &tmp))
+ "transport", "MANIPULATE_DELAY_IN", &tmp) && (tmp > 0))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Delaying inbound traffic
for %llu ms\n",
(unsigned long long) tmp);
@@ -599,7 +600,7 @@
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (GST_cfg,
- "transport", "MANIPULATE_DELAY_OUT", &tmp))
+ "transport", "MANIPULATE_DELAY_OUT", &tmp) && (tmp > 0))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Delaying outbound traffic
for %llu ms\n",
(unsigned long long) tmp);
Modified: gnunet/src/transport/test_transport_api_manipulation_cfg.c
===================================================================
--- gnunet/src/transport/test_transport_api_manipulation_cfg.c 2013-05-17
11:37:35 UTC (rev 27197)
+++ gnunet/src/transport/test_transport_api_manipulation_cfg.c 2013-05-17
12:59:36 UTC (rev 27198)
@@ -20,12 +20,13 @@
/**
* @file transport/test_transport_api_manipulation_send_tcp.c
* @brief base test case for transport traffic manipulation implementation
+ * based onf cfg
*
- * This test case will setup 2 peers and connect them, the first message
- * will be sent without manipulation, then a send delay of 1 second will
- * be configured and 1 more message will be sent. Time will be measured.
+ * Peer 1 has inbound and outbound delay of 100ms
+ * Peer 2 has no inbound and outbound delay
*
- * In addition the distance on receiver side will be manipulated to be 10
+ * We send a request from P1 to P2 and expect delay of >= TEST_DELAY ms
+ * Then we send response from P2 to P1 and expect delay of >= TEST_DELAY ms
*/
#include "platform.h"
#include "gnunet_transport_service.h"
@@ -43,8 +44,12 @@
#define TEST_MESSAGE_SIZE 2600
-#define TEST_MESSAGE_TYPE 12345
+#define TEST_REQUEST_MESSAGE_TYPE 12345
+#define TEST_RESPONSE_MESSAGE_TYPE 12346
+
+#define TEST_DELAY 100
+
static char *test_source;
static char *test_plugin;
@@ -77,14 +82,9 @@
static char *cfg_file_p2;
-static int messages_recv;
+static struct GNUNET_TIME_Absolute start_request;
+static struct GNUNET_TIME_Absolute start_response;
-static struct GNUNET_TIME_Absolute start_normal;
-static struct GNUNET_TIME_Relative dur_normal;
-
-static struct GNUNET_TIME_Absolute start_delayed;
-static struct GNUNET_TIME_Relative dur_delayed;
-
static void
end ()
{
@@ -157,80 +157,68 @@
}
-static void
-sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-static void
-notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message)
+static size_t
+notify_request_ready (void *cls, size_t size, void *buf)
{
struct PeerContext *p = cls;
- struct PeerContext *t = NULL;
+ struct GNUNET_MessageHeader *hdr;
- if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
- t = p1;
- if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
- t = p2;
- GNUNET_assert (t != NULL);
+ th = NULL;
- char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+ if (buf == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Timeout occurred while waiting for transmit_ready\n");
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ ok = 42;
+ return 0;
+ }
+ GNUNET_assert (size >= TEST_MESSAGE_SIZE);
+ if (buf != NULL)
+ {
+ memset (buf, '\0', TEST_MESSAGE_SIZE);
+ hdr = buf;
+ hdr->size = htons (TEST_MESSAGE_SIZE);
+ hdr->type = htons (TEST_REQUEST_MESSAGE_TYPE);
+ }
+
+ char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer %u (`%4s') received message of type %d and size %u size
from peer %u (`%4s')!\n",
- p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
- GNUNET_i2s (&t->id));
+ "Sending request message from peer %u (`%4s') with type %u and
size %u bytes to peer %u (`%4s')\n",
+ p1->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
+ GNUNET_i2s (&p->id));
GNUNET_free (ps);
+ return TEST_MESSAGE_SIZE;
+}
- if ((TEST_MESSAGE_TYPE == ntohs (message->type)) &&
- (TEST_MESSAGE_SIZE == ntohs (message->size)))
- {
- ok = 0;
- }
- else
- {
- GNUNET_break (0);
- ok = 1;
- end ();
+static void
+sendtask_request_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
+{
+ send_task = GNUNET_SCHEDULER_NO_TASK;
+
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- }
+ char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
- if (0 == messages_recv)
- {
- /* Received outbound only delayed message message */
- dur_normal = GNUNET_TIME_absolute_get_duration(start_normal);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received outbound message %u after %llu\n",
- messages_recv,
- (long long unsigned int) dur_normal.rel_value);
- send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
- }
- if (1 == messages_recv)
- {
- /* Received outbound and inbound delayed message */
- dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received delayed message %u after %llu\n",
- messages_recv,
- (long long unsigned int) dur_delayed.rel_value);
- if (dur_delayed.rel_value < (dur_normal.rel_value * 1.80))
- {
- GNUNET_break (0);
- ok += 1;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Outbound and inbound delayed message was not delayed
correctly: took only %llu\n",
- (long long unsigned int) dur_delayed.rel_value);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
+ p1->no, GNUNET_i2s (&p1->id), p2->no, receiver_s);
+ GNUNET_free (receiver_s);
- /* shutdown */
- end ();
- }
- messages_recv ++;
+ s_sending = GNUNET_YES;
+ start_request = GNUNET_TIME_absolute_get();
+ th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id,
TEST_MESSAGE_SIZE, 0,
+ TIMEOUT_TRANSMIT,
¬ify_request_ready,
+ p2);
}
static size_t
-notify_ready (void *cls, size_t size, void *buf)
+notify_response_ready (void *cls, size_t size, void *buf)
{
struct PeerContext *p = cls;
struct GNUNET_MessageHeader *hdr;
@@ -239,7 +227,7 @@
if (buf == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Timeout occurred while waiting for transmit_ready\n");
if (GNUNET_SCHEDULER_NO_TASK != die_task)
GNUNET_SCHEDULER_cancel (die_task);
@@ -254,31 +242,21 @@
memset (buf, '\0', TEST_MESSAGE_SIZE);
hdr = buf;
hdr->size = htons (TEST_MESSAGE_SIZE);
- hdr->type = htons (TEST_MESSAGE_TYPE);
+ hdr->type = htons (TEST_RESPONSE_MESSAGE_TYPE);
}
- if (0 == messages_recv)
- {
- start_normal = GNUNET_TIME_absolute_get();
- }
- if (1 == messages_recv)
- {
- start_delayed = GNUNET_TIME_absolute_get();
- }
-
- char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
+ char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer %u (`%4s') sending message with type %u and size %u bytes
to peer %u (`%4s')\n",
- p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
+ "Sending response message from peer %u (`%4s') with type %u and
size %u bytes to peer %u (`%4s')\n",
+ p1->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
GNUNET_i2s (&p->id));
GNUNET_free (ps);
return TEST_MESSAGE_SIZE;
}
-
static void
-sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+sendtask_response_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
send_task = GNUNET_SCHEDULER_NO_TASK;
@@ -291,16 +269,82 @@
p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
GNUNET_free (receiver_s);
-
-
s_sending = GNUNET_YES;
+ start_response = GNUNET_TIME_absolute_get();
th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id,
TEST_MESSAGE_SIZE, 0,
- TIMEOUT_TRANSMIT, ¬ify_ready,
+ TIMEOUT_TRANSMIT,
¬ify_response_ready,
p1);
}
+
static void
+notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct PeerContext *p = cls;
+ struct PeerContext *t = NULL;
+ struct GNUNET_TIME_Relative duration;
+
+ if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
+ t = p1;
+ if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
+ t = p2;
+ GNUNET_assert (t != NULL);
+
+ char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%4s') received message of type %d and size %u size
from peer %u (`%4s')!\n",
+ p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
+ GNUNET_i2s (&t->id));
+ GNUNET_free (ps);
+
+ switch (ntohs (message->type)) {
+ case TEST_REQUEST_MESSAGE_TYPE:
+ duration =
GNUNET_TIME_absolute_get_difference(start_request,
+ GNUNET_TIME_absolute_get());
+ if (duration.rel_value >= TEST_DELAY)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Request message was delayed for %llu ms\n",
+
duration.rel_value);
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Request message was delayed for %llu ms, should
be %u ms\n",
+
duration.rel_value, TEST_DELAY);
+ ok = 1;
+ }
+
+ /* Send response */
+ send_task = GNUNET_SCHEDULER_add_now
(&sendtask_response_task, NULL);
+ return;
+ break;
+ case TEST_RESPONSE_MESSAGE_TYPE:
+ duration =
GNUNET_TIME_absolute_get_difference(start_response,
+ GNUNET_TIME_absolute_get());
+ if (duration.rel_value >= TEST_DELAY)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Response message was delayed for %llu ms\n",
duration);
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Response message was delayed for %llu ms, should
be %u ms\n",
+
duration.rel_value, TEST_DELAY);
+ ok = 1;
+ }
+ /* Done */
+ ok = 1;
+ end();
+ break;
+ default:
+ break;
+ }
+}
+
+
+
+static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
static int c;
@@ -353,7 +397,7 @@
GNUNET_free (p1_c);
s_connected = GNUNET_YES;
- send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
+ send_task = GNUNET_SCHEDULER_add_now (&sendtask_request_task, NULL);
}
@@ -376,15 +420,7 @@
"Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (sender_c);
- /*
- struct GNUNET_ATS_Information ats[2];
- ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
- ats[0].value = htonl (1000);
- ats[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
- ats[1].value = htonl (10);
- GNUNET_TRANSPORT_set_traffic_metric (p1->th, &p2->id, TM_RECEIVE, ats, 2);
-*/
cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2,
&testing_connect_cb,
NULL);
Modified: gnunet/src/transport/test_transport_api_manipulation_cfg_peer2.conf
===================================================================
--- gnunet/src/transport/test_transport_api_manipulation_cfg_peer2.conf
2013-05-17 11:37:35 UTC (rev 27197)
+++ gnunet/src/transport/test_transport_api_manipulation_cfg_peer2.conf
2013-05-17 12:59:36 UTC (rev 27198)
@@ -27,5 +27,5 @@
PORT = 12010
PLUGINS = tcp
UNIXPATH = /tmp/gnunet-p2-service-transport.sock
-MANIPULATE_DELAY_IN = 100
-MANIPULATE_DELAY_OUT = 100
+#MANIPULATE_DELAY_IN = 0
+#MANIPULATE_DELAY_OUT = 0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27198 - gnunet/src/transport,
gnunet <=