diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-05-20 11:37:19 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-05-20 11:37:19 +0000 |
commit | e2d3ca4d4eee401515f94382c160fd9a65230a3c (patch) | |
tree | 3f59d3b0b1e696770b497b1c9d1e53df69a59ec7 /src/transport | |
parent | 515580c7f27b87831b6b5d4207c72c8acab53ca1 (diff) | |
download | gnunet-e2d3ca4d4eee401515f94382c160fd9a65230a3c.tar.gz gnunet-e2d3ca4d4eee401515f94382c160fd9a65230a3c.zip |
remove unreliability test
- update reliabilitility test: this test only ensures that all messages are delivered and are not corrupted
out of order delivery is not checked any longer
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/Makefile.am | 54 | ||||
-rw-r--r-- | src/transport/template_cfg_peer1.conf | 2 | ||||
-rw-r--r-- | src/transport/template_cfg_peer2.conf | 2 | ||||
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 403 | ||||
-rw-r--r-- | src/transport/test_transport_api_reliability_udp_peer1.conf (renamed from src/transport/test_transport_api_unreliability_udp_peer1.conf) | 0 | ||||
-rw-r--r-- | src/transport/test_transport_api_reliability_udp_peer2.conf (renamed from src/transport/test_transport_api_unreliability_udp_peer2.conf) | 0 | ||||
-rw-r--r-- | src/transport/test_transport_api_reliability_unix_peer1.conf (renamed from src/transport/test_transport_api_unreliability_unix_peer1.conf) | 0 | ||||
-rw-r--r-- | src/transport/test_transport_api_reliability_unix_peer2.conf (renamed from src/transport/test_transport_api_unreliability_unix_peer2.conf) | 0 | ||||
-rw-r--r-- | src/transport/test_transport_api_unreliability.c | 588 |
9 files changed, 267 insertions, 782 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 842e7455f..ce05e6d55 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -55,7 +55,6 @@ if LINUX | |||
55 | WLAN_API_TEST = test_transport_api_wlan | 55 | WLAN_API_TEST = test_transport_api_wlan |
56 | WLAN_TIMEOUT_TEST = test_transport_api_timeout_wlan | 56 | WLAN_TIMEOUT_TEST = test_transport_api_timeout_wlan |
57 | WLAN_REL_TEST = test_transport_api_reliability_wlan | 57 | WLAN_REL_TEST = test_transport_api_reliability_wlan |
58 | WLAN_UREL_TEST = test_transport_api_unreliability_wlan | ||
59 | WLAN_QUOTA_TEST = test_quota_compliance_wlan \ | 58 | WLAN_QUOTA_TEST = test_quota_compliance_wlan \ |
60 | test_quota_compliance_wlan_asymmetric | 59 | test_quota_compliance_wlan_asymmetric |
61 | endif | 60 | endif |
@@ -75,7 +74,6 @@ if HAVE_LIBBLUETOOTH | |||
75 | BT_API_TEST = test_transport_api_bluetooth | 74 | BT_API_TEST = test_transport_api_bluetooth |
76 | BT_TIMEOUT_TEST = test_transport_api_timeout_bluetooth | 75 | BT_TIMEOUT_TEST = test_transport_api_timeout_bluetooth |
77 | BT_REL_TEST = test_transport_api_reliability_bluetooth | 76 | BT_REL_TEST = test_transport_api_reliability_bluetooth |
78 | BT_UREL_TEST = test_transport_api_unreliability_bluetooth | ||
79 | BT_QUOTA_TEST = test_quota_compliance_bluetooth \ | 77 | BT_QUOTA_TEST = test_quota_compliance_bluetooth \ |
80 | test_quota_compliance_bluetooth_asymmetric | 78 | test_quota_compliance_bluetooth_asymmetric |
81 | endif | 79 | endif |
@@ -100,7 +98,7 @@ UNIX_PLUGIN_LA = libgnunet_plugin_transport_unix.la | |||
100 | UNIX_PLUGIN_TEST = test_transport_api_unix | 98 | UNIX_PLUGIN_TEST = test_transport_api_unix |
101 | UNIX_TEST = test_plugin_unix | 99 | UNIX_TEST = test_plugin_unix |
102 | UNIX_PLUGIN_TIMEOUT_TEST = test_transport_api_timeout_unix | 100 | UNIX_PLUGIN_TIMEOUT_TEST = test_transport_api_timeout_unix |
103 | UNIX_REL_TEST = test_transport_api_unreliability_unix | 101 | UNIX_REL_TEST = test_transport_api_reliability_unix |
104 | UNIX_QUOTA_TEST = test_quota_compliance_unix \ | 102 | UNIX_QUOTA_TEST = test_quota_compliance_unix \ |
105 | test_quota_compliance_unix_asymmetric | 103 | test_quota_compliance_unix_asymmetric |
106 | if LINUX | 104 | if LINUX |
@@ -430,8 +428,7 @@ check_PROGRAMS = \ | |||
430 | test_transport_api_manipulation_cfg \ | 428 | test_transport_api_manipulation_cfg \ |
431 | test_transport_api_reliability_tcp \ | 429 | test_transport_api_reliability_tcp \ |
432 | test_transport_api_reliability_tcp_nat \ | 430 | test_transport_api_reliability_tcp_nat \ |
433 | test_transport_api_unreliability_udp \ | 431 | test_transport_api_reliability_udp \ |
434 | test_transport_api_unreliability_constant_udp \ | ||
435 | $(UNIX_REL_TEST) \ | 432 | $(UNIX_REL_TEST) \ |
436 | $(HTTP_REL_TEST) \ | 433 | $(HTTP_REL_TEST) \ |
437 | $(HTTPS_REL_TEST) \ | 434 | $(HTTPS_REL_TEST) \ |
@@ -498,8 +495,7 @@ TESTS = \ | |||
498 | test_transport_api_manipulation_cfg \ | 495 | test_transport_api_manipulation_cfg \ |
499 | test_transport_api_reliability_tcp \ | 496 | test_transport_api_reliability_tcp \ |
500 | test_transport_api_reliability_tcp_nat \ | 497 | test_transport_api_reliability_tcp_nat \ |
501 | test_transport_api_unreliability_udp \ | 498 | test_transport_api_reliability_udp \ |
502 | test_transport_api_unreliability_constant_udp \ | ||
503 | $(UNIX_REL_TEST) \ | 499 | $(UNIX_REL_TEST) \ |
504 | $(HTTP_REL_TEST) \ | 500 | $(HTTP_REL_TEST) \ |
505 | $(HTTPS_REL_TEST) \ | 501 | $(HTTPS_REL_TEST) \ |
@@ -833,14 +829,6 @@ test_transport_api_reliability_tcp_nat_LDADD = \ | |||
833 | $(top_builddir)/src/util/libgnunetutil.la \ | 829 | $(top_builddir)/src/util/libgnunetutil.la \ |
834 | $(top_builddir)/src/transport/libgnunettransporttesting.la | 830 | $(top_builddir)/src/transport/libgnunettransporttesting.la |
835 | 831 | ||
836 | test_transport_api_reliability_wlan_SOURCES = \ | ||
837 | test_transport_api_reliability.c | ||
838 | test_transport_api_reliability_wlan_LDADD = \ | ||
839 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
840 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
841 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
842 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
843 | |||
844 | test_transport_api_reliability_bluetooth_SOURCES = \ | 832 | test_transport_api_reliability_bluetooth_SOURCES = \ |
845 | test_transport_api_reliability.c | 833 | test_transport_api_reliability.c |
846 | test_transport_api_reliability_bluetooth_LDADD = \ | 834 | test_transport_api_reliability_bluetooth_LDADD = \ |
@@ -849,17 +837,9 @@ test_transport_api_reliability_bluetooth_LDADD = \ | |||
849 | $(top_builddir)/src/util/libgnunetutil.la \ | 837 | $(top_builddir)/src/util/libgnunetutil.la \ |
850 | $(top_builddir)/src/transport/libgnunettransporttesting.la | 838 | $(top_builddir)/src/transport/libgnunettransporttesting.la |
851 | 839 | ||
852 | test_transport_api_unreliability_wlan_SOURCES = \ | 840 | test_transport_api_reliability_wlan_SOURCES = \ |
853 | test_transport_api_unreliability.c | 841 | test_transport_api_reliability.c |
854 | test_transport_api_unreliability_wlan_LDADD = \ | 842 | test_transport_api_reliability_wlan_LDADD = \ |
855 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
856 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
857 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
858 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
859 | |||
860 | test_transport_api_unreliability_bluetooth_SOURCES = \ | ||
861 | test_transport_api_unreliability.c | ||
862 | test_transport_api_unreliability_bluetooth_LDADD = \ | ||
863 | $(top_builddir)/src/transport/libgnunettransport.la \ | 843 | $(top_builddir)/src/transport/libgnunettransport.la \ |
864 | $(top_builddir)/src/hello/libgnunethello.la \ | 844 | $(top_builddir)/src/hello/libgnunethello.la \ |
865 | $(top_builddir)/src/util/libgnunetutil.la \ | 845 | $(top_builddir)/src/util/libgnunetutil.la \ |
@@ -996,25 +976,17 @@ test_transport_api_reliability_https_LDADD = \ | |||
996 | $(top_builddir)/src/util/libgnunetutil.la \ | 976 | $(top_builddir)/src/util/libgnunetutil.la \ |
997 | $(top_builddir)/src/transport/libgnunettransporttesting.la | 977 | $(top_builddir)/src/transport/libgnunettransporttesting.la |
998 | 978 | ||
999 | test_transport_api_unreliability_unix_SOURCES = \ | 979 | test_transport_api_reliability_unix_SOURCES = \ |
1000 | test_transport_api_unreliability.c | 980 | test_transport_api_reliability.c |
1001 | test_transport_api_unreliability_unix_LDADD = \ | 981 | test_transport_api_reliability_unix_LDADD = \ |
1002 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
1003 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
1004 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
1005 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
1006 | |||
1007 | test_transport_api_unreliability_udp_SOURCES = \ | ||
1008 | test_transport_api_unreliability.c | ||
1009 | test_transport_api_unreliability_udp_LDADD = \ | ||
1010 | $(top_builddir)/src/transport/libgnunettransport.la \ | 982 | $(top_builddir)/src/transport/libgnunettransport.la \ |
1011 | $(top_builddir)/src/hello/libgnunethello.la \ | 983 | $(top_builddir)/src/hello/libgnunethello.la \ |
1012 | $(top_builddir)/src/util/libgnunetutil.la \ | 984 | $(top_builddir)/src/util/libgnunetutil.la \ |
1013 | $(top_builddir)/src/transport/libgnunettransporttesting.la | 985 | $(top_builddir)/src/transport/libgnunettransporttesting.la |
1014 | 986 | ||
1015 | test_transport_api_unreliability_constant_udp_SOURCES = \ | 987 | test_transport_api_reliability_udp_SOURCES = \ |
1016 | test_transport_api_unreliability_constant.c | 988 | test_transport_api_reliability.c |
1017 | test_transport_api_unreliability_constant_udp_LDADD = \ | 989 | test_transport_api_reliability_udp_LDADD = \ |
1018 | $(top_builddir)/src/transport/libgnunettransport.la \ | 990 | $(top_builddir)/src/transport/libgnunettransport.la \ |
1019 | $(top_builddir)/src/hello/libgnunethello.la \ | 991 | $(top_builddir)/src/hello/libgnunethello.la \ |
1020 | $(top_builddir)/src/util/libgnunetutil.la \ | 992 | $(top_builddir)/src/util/libgnunetutil.la \ |
@@ -1249,8 +1221,6 @@ test_transport_api_timeout_http_peer1.conf\ | |||
1249 | test_transport_api_timeout_http_peer2.conf\ | 1221 | test_transport_api_timeout_http_peer2.conf\ |
1250 | test_transport_api_timeout_https_peer1.conf\ | 1222 | test_transport_api_timeout_https_peer1.conf\ |
1251 | test_transport_api_timeout_https_peer2.conf\ | 1223 | test_transport_api_timeout_https_peer2.conf\ |
1252 | test_transport_api_unreliability_constant_udp_peer1.conf\ | ||
1253 | test_transport_api_unreliability_constant_udp_peer2.conf\ | ||
1254 | test_transport_blacklisting_cfg_peer1.conf \ | 1224 | test_transport_blacklisting_cfg_peer1.conf \ |
1255 | test_transport_blacklisting_cfg_peer2.conf \ | 1225 | test_transport_blacklisting_cfg_peer2.conf \ |
1256 | test_transport_blacklisting_cfg_blp_peer1_full.conf\ | 1226 | test_transport_blacklisting_cfg_blp_peer1_full.conf\ |
diff --git a/src/transport/template_cfg_peer1.conf b/src/transport/template_cfg_peer1.conf index 3042ce862..daeb63744 100644 --- a/src/transport/template_cfg_peer1.conf +++ b/src/transport/template_cfg_peer1.conf | |||
@@ -4,7 +4,7 @@ GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/ | |||
4 | 4 | ||
5 | [nat] | 5 | [nat] |
6 | RETURN_LOCAL_ADDRESSES = YES | 6 | RETURN_LOCAL_ADDRESSES = YES |
7 | DISABLEV6 = NO | 7 | #DISABLEV6 = YES |
8 | 8 | ||
9 | [transport-tcp] | 9 | [transport-tcp] |
10 | PORT = 12000 | 10 | PORT = 12000 |
diff --git a/src/transport/template_cfg_peer2.conf b/src/transport/template_cfg_peer2.conf index b5ba77b76..68fb74a60 100644 --- a/src/transport/template_cfg_peer2.conf +++ b/src/transport/template_cfg_peer2.conf | |||
@@ -4,7 +4,7 @@ GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/ | |||
4 | 4 | ||
5 | [nat] | 5 | [nat] |
6 | RETURN_LOCAL_ADDRESSES = YES | 6 | RETURN_LOCAL_ADDRESSES = YES |
7 | DISABLEV6 = NO | 7 | #DISABLEV6 = NO |
8 | 8 | ||
9 | [transport-tcp] | 9 | [transport-tcp] |
10 | PORT = 12100 | 10 | PORT = 12100 |
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index d2a78d17f..07213722e 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -21,87 +21,141 @@ | |||
21 | * @file transport/test_transport_api_reliability.c | 21 | * @file transport/test_transport_api_reliability.c |
22 | * @brief base test case for transport implementations | 22 | * @brief base test case for transport implementations |
23 | * | 23 | * |
24 | * This test case serves as a base for tcp and http | 24 | * This test case serves ensures that messages are reliably sent between peers |
25 | * transport test cases to check that the transports | 25 | * |
26 | * achieve reliable message delivery. | 26 | * This test sends TOTAL_MSGS with message type MTYPE from peer 1 to peer 2 |
27 | * and ensures that all message were received. | ||
27 | */ | 28 | */ |
28 | #include "platform.h" | 29 | #include "platform.h" |
29 | #include "gnunet_transport_service.h" | 30 | #include "gnunet_transport_service.h" |
30 | #include "gauger.h" | 31 | #include "gauger.h" |
31 | #include "transport-testing.h" | 32 | #include "transport-testing.h" |
33 | |||
34 | /** | ||
35 | * Total number of messages to send | ||
36 | * | ||
37 | * Note that this value must not significantly exceed | ||
38 | * 'MAX_PENDING' in 'gnunet-service-transport_clients.c', otherwise | ||
39 | * messages may be dropped even for a reliable transport. | ||
40 | */ | ||
41 | #define TOTAL_MSGS (1024 * 3) | ||
42 | |||
43 | /** | ||
44 | * Message type of test messages | ||
45 | */ | ||
46 | #define MTYPE 12345 | ||
47 | |||
32 | /** | 48 | /** |
33 | * Testcase timeout | 49 | * Testcase timeout |
34 | */ | 50 | */ |
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 51 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900) |
36 | 52 | ||
37 | /** | 53 | /** |
38 | * How long until we give up on transmitting the message? | 54 | * How long until we give up on transmitting the message? |
39 | */ | 55 | */ |
40 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 56 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
57 | |||
58 | |||
59 | /** | ||
60 | * Struct for the test message | ||
61 | */ | ||
62 | GNUNET_NETWORK_STRUCT_BEGIN | ||
41 | 63 | ||
64 | struct TestMessage | ||
65 | { | ||
66 | struct GNUNET_MessageHeader header; | ||
67 | uint32_t num; | ||
68 | }; | ||
69 | GNUNET_NETWORK_STRUCT_END | ||
42 | 70 | ||
43 | static char *test_source; | ||
44 | 71 | ||
72 | /** | ||
73 | * Name of the plugin to test | ||
74 | */ | ||
45 | static char *test_plugin; | 75 | static char *test_plugin; |
46 | 76 | ||
77 | /** | ||
78 | * Name of the test | ||
79 | */ | ||
47 | static char *test_name; | 80 | static char *test_name; |
48 | 81 | ||
82 | /** | ||
83 | * Return value of the test | ||
84 | */ | ||
49 | static int ok; | 85 | static int ok; |
50 | 86 | ||
51 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 87 | /** |
52 | 88 | * Context of peer 1 | |
89 | */ | ||
53 | struct PeerContext *p1; | 90 | struct PeerContext *p1; |
54 | 91 | ||
92 | /** | ||
93 | * Configuration file of peer 1 | ||
94 | */ | ||
95 | char *cfg_file_p1; | ||
96 | |||
97 | /** | ||
98 | * Context of peer 2 | ||
99 | */ | ||
55 | struct PeerContext *p2; | 100 | struct PeerContext *p2; |
56 | 101 | ||
57 | struct PeerContext *sender; | 102 | /** |
103 | * Configuration file of peer 1 | ||
104 | */ | ||
105 | char *cfg_file_p2; | ||
58 | 106 | ||
59 | struct PeerContext *receiver; | 107 | /** |
108 | * Timeout task | ||
109 | */ | ||
110 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
60 | 111 | ||
112 | /** | ||
113 | * Transport transmit handle used | ||
114 | */ | ||
61 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 115 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
62 | 116 | ||
63 | char *cfg_file_p1; | 117 | /** |
64 | 118 | * Transport testing handle | |
65 | char *cfg_file_p2; | 119 | */ |
66 | |||
67 | struct GNUNET_TRANSPORT_TESTING_handle *tth; | 120 | struct GNUNET_TRANSPORT_TESTING_handle *tth; |
68 | 121 | ||
69 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
70 | |||
71 | |||
72 | /* | 122 | /* |
73 | * Testcase specific declarations | 123 | * Total amount of bytes sent |
74 | */ | 124 | */ |
125 | static unsigned long long total_bytes; | ||
75 | 126 | ||
76 | /** | 127 | /** |
77 | * Note that this value must not significantly exceed | 128 | * Time of start |
78 | * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise | ||
79 | * messages may be dropped even for a reliable transport. | ||
80 | */ | 129 | */ |
81 | #define TOTAL_MSGS (1024 * 2) | 130 | static struct GNUNET_TIME_Absolute start_time; |
82 | |||
83 | #define MTYPE 12345 | ||
84 | |||
85 | GNUNET_NETWORK_STRUCT_BEGIN | ||
86 | |||
87 | struct TestMessage | ||
88 | { | ||
89 | struct GNUNET_MessageHeader header; | ||
90 | uint32_t num; | ||
91 | }; | ||
92 | GNUNET_NETWORK_STRUCT_END | ||
93 | 131 | ||
132 | /** | ||
133 | * No. of message currently scheduled to be send | ||
134 | */ | ||
94 | static int msg_scheduled; | 135 | static int msg_scheduled; |
136 | |||
137 | /** | ||
138 | * No. of last message sent | ||
139 | */ | ||
95 | static int msg_sent; | 140 | static int msg_sent; |
96 | static int msg_recv_expected; | 141 | |
142 | /** | ||
143 | * No. of last message received | ||
144 | */ | ||
97 | static int msg_recv; | 145 | static int msg_recv; |
98 | 146 | ||
99 | static int test_failed; | ||
100 | static int test_connected; | 147 | static int test_connected; |
148 | static int test_sending; | ||
149 | static int test_send_timeout; | ||
101 | 150 | ||
102 | static unsigned long long total_bytes; | ||
103 | 151 | ||
104 | static struct GNUNET_TIME_Absolute start_time; | 152 | /** |
153 | * Bitmap storing which messages were received | ||
154 | */ | ||
155 | |||
156 | static char bitmap[TOTAL_MSGS / 8]; | ||
157 | |||
158 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
105 | 159 | ||
106 | /* | 160 | /* |
107 | * END Testcase specific declarations | 161 | * END Testcase specific declarations |
@@ -113,6 +167,8 @@ static struct GNUNET_TIME_Absolute start_time; | |||
113 | #define OKPP do { ok++; } while (0) | 167 | #define OKPP do { ok++; } while (0) |
114 | #endif | 168 | #endif |
115 | 169 | ||
170 | static int | ||
171 | get_bit (const char *map, unsigned int bit); | ||
116 | 172 | ||
117 | static void | 173 | static void |
118 | end () | 174 | end () |
@@ -121,15 +177,15 @@ end () | |||
121 | unsigned long long rate; | 177 | unsigned long long rate; |
122 | char *value_name; | 178 | char *value_name; |
123 | 179 | ||
124 | |||
125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | 180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); |
126 | 181 | ||
182 | /* Calculcate statistics */ | ||
127 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | 183 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; |
128 | rate = (1000LL * 1000LL * total_bytes) / (1024 * delta); | 184 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); |
129 | FPRINTF (stderr, "\nThroughput was %llu KiBytes/s\n", | 185 | FPRINTF (stderr, "\nThroughput was %llu KiBytes/s\n", |
130 | rate); | 186 | rate); |
131 | 187 | ||
132 | GNUNET_asprintf (&value_name, "reliable_%s", test_plugin); | 188 | GNUNET_asprintf (&value_name, "unreliable_%s", test_plugin); |
133 | GAUGER ("TRANSPORT", value_name, (int) rate, | 189 | GAUGER ("TRANSPORT", value_name, (int) rate, |
134 | "kb/s"); | 190 | "kb/s"); |
135 | GNUNET_free (value_name); | 191 | GNUNET_free (value_name); |
@@ -143,16 +199,31 @@ end () | |||
143 | 199 | ||
144 | if (cc != NULL) | 200 | if (cc != NULL) |
145 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | 201 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); |
202 | cc = NULL; | ||
146 | 203 | ||
147 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | 204 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
148 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | 205 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
149 | 206 | ||
150 | GNUNET_TRANSPORT_TESTING_done (tth); | 207 | GNUNET_TRANSPORT_TESTING_done (tth); |
208 | |||
209 | ok = 0; | ||
210 | |||
211 | int i; | ||
212 | |||
213 | for (i = 0; i < TOTAL_MSGS; i++) | ||
214 | { | ||
215 | if (get_bit (bitmap, i) == 0) | ||
216 | { | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); | ||
218 | ok = -1; | ||
219 | } | ||
220 | } | ||
151 | } | 221 | } |
152 | 222 | ||
153 | static void | 223 | static void |
154 | end_badly () | 224 | end_badly () |
155 | { | 225 | { |
226 | int i; | ||
156 | die_task = GNUNET_SCHEDULER_NO_TASK; | 227 | die_task = GNUNET_SCHEDULER_NO_TASK; |
157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
158 | 229 | ||
@@ -161,20 +232,34 @@ end_badly () | |||
161 | else | 232 | else |
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); | 233 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); |
163 | 234 | ||
235 | if (test_sending == GNUNET_NO) | ||
236 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
237 | "Testcase did not send any messages before timeout\n"); | ||
238 | if (test_send_timeout == GNUNET_YES) | ||
239 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
240 | "Test had timeout while waiting to send data\n"); | ||
241 | for (i = 0; i < TOTAL_MSGS; i++) | ||
242 | { | ||
243 | if (get_bit (bitmap, i) == 0) | ||
244 | { | ||
245 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); | ||
246 | ok = -1; | ||
247 | } | ||
248 | } | ||
249 | |||
164 | if (th != NULL) | 250 | if (th != NULL) |
165 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 251 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
166 | th = NULL; | 252 | th = NULL; |
167 | 253 | ||
168 | if (cc != NULL) | 254 | if (cc != NULL) |
169 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | 255 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); |
256 | cc = NULL; | ||
170 | 257 | ||
171 | if (p1 != NULL) | 258 | if (p1 != NULL) |
172 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | 259 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
173 | if (p2 != NULL) | 260 | if (p2 != NULL) |
174 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | 261 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
175 | |||
176 | GNUNET_TRANSPORT_TESTING_done (tth); | 262 | GNUNET_TRANSPORT_TESTING_done (tth); |
177 | |||
178 | ok = GNUNET_SYSERR; | 263 | ok = GNUNET_SYSERR; |
179 | } | 264 | } |
180 | 265 | ||
@@ -185,84 +270,126 @@ get_size (unsigned int iter) | |||
185 | unsigned int ret; | 270 | unsigned int ret; |
186 | 271 | ||
187 | ret = (iter * iter * iter); | 272 | ret = (iter * iter * iter); |
273 | |||
274 | #ifndef LINUX | ||
275 | /* FreeBSD/OSX etc. Unix DGRAMs do not work | ||
276 | * with large messages */ | ||
277 | if (0 == strcmp ("unix", test_plugin)) | ||
278 | return sizeof (struct TestMessage) + (ret % 1024); | ||
279 | #endif | ||
188 | return sizeof (struct TestMessage) + (ret % 60000); | 280 | return sizeof (struct TestMessage) + (ret % 60000); |
189 | } | 281 | } |
190 | 282 | ||
191 | 283 | ||
284 | /** | ||
285 | * Sets a bit active in the bitmap. | ||
286 | * | ||
287 | * @param bitIdx which bit to set | ||
288 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | ||
289 | */ | ||
290 | static int | ||
291 | set_bit (unsigned int bitIdx) | ||
292 | { | ||
293 | size_t arraySlot; | ||
294 | unsigned int targetBit; | ||
295 | |||
296 | if (bitIdx >= sizeof (bitmap) * 8) | ||
297 | { | ||
298 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "tried to set bit %d of %d(!?!?)\n", | ||
299 | bitIdx, sizeof (bitmap) * 8); | ||
300 | return GNUNET_SYSERR; | ||
301 | } | ||
302 | arraySlot = bitIdx / 8; | ||
303 | targetBit = (1L << (bitIdx % 8)); | ||
304 | bitmap[arraySlot] |= targetBit; | ||
305 | return GNUNET_OK; | ||
306 | } | ||
307 | |||
308 | /** | ||
309 | * Obtain a bit from bitmap. | ||
310 | * @param map the bitmap | ||
311 | * @param bit index from bitmap | ||
312 | * | ||
313 | * @return Bit \a bit from hashcode \a code | ||
314 | */ | ||
315 | static int | ||
316 | get_bit (const char *map, unsigned int bit) | ||
317 | { | ||
318 | if (bit > TOTAL_MSGS) | ||
319 | { | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit, | ||
321 | sizeof (bitmap) * 8); | ||
322 | return 0; | ||
323 | } | ||
324 | return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; | ||
325 | } | ||
326 | |||
327 | |||
192 | static void | 328 | static void |
193 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 329 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, |
194 | const struct GNUNET_MessageHeader *message) | 330 | const struct GNUNET_MessageHeader *message) |
195 | { | 331 | { |
196 | static int n; | 332 | static int n; |
333 | |||
197 | unsigned int s; | 334 | unsigned int s; |
198 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 335 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
199 | const struct TestMessage *hdr; | 336 | const struct TestMessage *hdr; |
200 | 337 | ||
201 | hdr = (const struct TestMessage *) message; | 338 | hdr = (const struct TestMessage *) message; |
202 | s = get_size (n); | 339 | |
203 | if (MTYPE != ntohs (message->type)) | 340 | if (MTYPE != ntohs (message->type)) |
204 | return; | 341 | return; |
205 | msg_recv_expected = n; | ||
206 | msg_recv = ntohl (hdr->num); | 342 | msg_recv = ntohl (hdr->num); |
207 | if (ntohs (message->size) != (s)) | 343 | s = get_size (ntohl (hdr->num)); |
208 | { | 344 | |
209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 345 | if (ntohs (message->size) != s) |
210 | "Expected message %u of size %u, got %u bytes of message %u\n", | ||
211 | n, s, ntohs (message->size), ntohl (hdr->num)); | ||
212 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
213 | GNUNET_SCHEDULER_cancel (die_task); | ||
214 | test_failed = GNUNET_YES; | ||
215 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
216 | return; | ||
217 | } | ||
218 | if (ntohl (hdr->num) != n) | ||
219 | { | 346 | { |
220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 347 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
221 | "Expected message %u of size %u, got %u bytes of message %u\n", | 348 | "Expected message %u of size %u, got %u bytes of message %u\n", |
222 | n, s, ntohs (message->size), ntohl (hdr->num)); | 349 | ntohl (hdr->num), s, ntohs (message->size), ntohl (hdr->num)); |
223 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 350 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
224 | GNUNET_SCHEDULER_cancel (die_task); | 351 | GNUNET_SCHEDULER_cancel (die_task); |
225 | test_failed = GNUNET_YES; | 352 | test_sending = GNUNET_YES; |
226 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 353 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
227 | return; | 354 | return; |
228 | } | 355 | } |
229 | memset (cbuf, n, s - sizeof (struct TestMessage)); | 356 | |
357 | memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage)); | ||
230 | if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) | 358 | if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) |
231 | { | 359 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
233 | "Expected message %u with bits %u, but body did not match at position %u\n", n, | 361 | "Expected message %u with bits %u, but body did not match\n", |
234 | (unsigned char) n); | 362 | ntohl (hdr->num), (unsigned char) n); |
235 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 363 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
236 | GNUNET_SCHEDULER_cancel (die_task); | 364 | GNUNET_SCHEDULER_cancel (die_task); |
237 | test_failed = GNUNET_YES; | 365 | test_sending = GNUNET_YES; |
238 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 366 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
239 | return; | 367 | return; |
240 | } | 368 | } |
241 | #if VERBOSE | 369 | #if VERBOSE |
242 | if (ntohl (hdr->num) % 5000 == 0) | 370 | if (ntohl (hdr->num) % 5 == 0) |
243 | { | 371 | { |
244 | struct PeerContext *p = cls; | 372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n", |
245 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 373 | ntohl (hdr->num), ntohs (message->size)); |
246 | |||
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
248 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", | ||
249 | p->no, ps, ntohl (hdr->num), ntohs (message->size), | ||
250 | GNUNET_i2s (peer)); | ||
251 | GNUNET_free (ps); | ||
252 | } | 374 | } |
253 | #endif | 375 | #endif |
254 | n++; | 376 | n++; |
377 | if (GNUNET_SYSERR == set_bit (ntohl (hdr->num))) | ||
378 | { | ||
379 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
380 | _("Message id %u is bigger than maxmimum number of messages %u expected\n"), | ||
381 | ntohl (hdr->num), TOTAL_MSGS); | ||
382 | } | ||
383 | test_sending = GNUNET_YES; | ||
255 | if (0 == (n % (TOTAL_MSGS / 100))) | 384 | if (0 == (n % (TOTAL_MSGS / 100))) |
256 | { | 385 | { |
257 | FPRINTF (stderr, "%s", "."); | 386 | FPRINTF (stderr, "%s", "."); |
258 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 387 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
259 | GNUNET_SCHEDULER_cancel (die_task); | 388 | GNUNET_SCHEDULER_cancel (die_task); |
260 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 389 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
261 | } | 390 | } |
262 | if (n == TOTAL_MSGS) | 391 | if (n == TOTAL_MSGS) |
263 | { | 392 | { |
264 | ok = 0; | ||
265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nAll messages received\n"); | ||
266 | end (); | 393 | end (); |
267 | } | 394 | } |
268 | } | 395 | } |
@@ -278,10 +405,12 @@ notify_ready (void *cls, size_t size, void *buf) | |||
278 | unsigned int ret; | 405 | unsigned int ret; |
279 | 406 | ||
280 | th = NULL; | 407 | th = NULL; |
408 | |||
281 | if (buf == NULL) | 409 | if (buf == NULL) |
282 | { | 410 | { |
411 | test_send_timeout = GNUNET_YES; | ||
283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 412 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
284 | "Timeout occurred while waiting for transmit_ready for message %u of %u\n", | 413 | "Timeout occurred while waiting for transmit_ready for msg %u of %u\n", |
285 | msg_scheduled, TOTAL_MSGS); | 414 | msg_scheduled, TOTAL_MSGS); |
286 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 415 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
287 | GNUNET_SCHEDULER_cancel (die_task); | 416 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -289,14 +418,15 @@ notify_ready (void *cls, size_t size, void *buf) | |||
289 | ok = 42; | 418 | ok = 42; |
290 | return 0; | 419 | return 0; |
291 | } | 420 | } |
292 | |||
293 | ret = 0; | 421 | ret = 0; |
294 | s = get_size (n); | 422 | s = get_size (n); |
295 | GNUNET_assert (size >= s); | 423 | GNUNET_assert (size >= s); |
296 | GNUNET_assert (buf != NULL); | 424 | GNUNET_assert (buf != NULL); |
425 | GNUNET_assert (n < TOTAL_MSGS); | ||
297 | cbuf = buf; | 426 | cbuf = buf; |
298 | do | 427 | do |
299 | { | 428 | { |
429 | GNUNET_assert (n < TOTAL_MSGS); | ||
300 | hdr.header.size = htons (s); | 430 | hdr.header.size = htons (s); |
301 | hdr.header.type = htons (MTYPE); | 431 | hdr.header.type = htons (MTYPE); |
302 | hdr.num = htonl (n); | 432 | hdr.num = htonl (n); |
@@ -305,17 +435,12 @@ notify_ready (void *cls, size_t size, void *buf) | |||
305 | ret += sizeof (struct TestMessage); | 435 | ret += sizeof (struct TestMessage); |
306 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); | 436 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); |
307 | ret += s - sizeof (struct TestMessage); | 437 | ret += s - sizeof (struct TestMessage); |
438 | |||
308 | #if VERBOSE | 439 | #if VERBOSE |
309 | if (n % 5000 == 0) | 440 | if (n % 5000 == 0) |
310 | { | 441 | { |
311 | 442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n, | |
312 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 443 | s); |
313 | |||
314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
315 | "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
316 | n, sender->no, GNUNET_i2s (&sender->id), receiver->no, | ||
317 | receiver_s); | ||
318 | GNUNET_free (receiver_s); | ||
319 | } | 444 | } |
320 | #endif | 445 | #endif |
321 | n++; | 446 | n++; |
@@ -323,26 +448,28 @@ notify_ready (void *cls, size_t size, void *buf) | |||
323 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 448 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
324 | break; /* sometimes pack buffer full, sometimes not */ | 449 | break; /* sometimes pack buffer full, sometimes not */ |
325 | } | 450 | } |
326 | while (size - ret >= s); | 451 | while ((size - ret >= s) && (n < TOTAL_MSGS)); |
327 | if (n < TOTAL_MSGS) | 452 | if (n < TOTAL_MSGS) |
328 | { | 453 | { |
329 | if (th == NULL) | 454 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, |
330 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, | 455 | TIMEOUT_TRANSMIT, |
331 | TIMEOUT_TRANSMIT, | 456 | ¬ify_ready, NULL); |
332 | ¬ify_ready, NULL); | ||
333 | msg_scheduled = n; | 457 | msg_scheduled = n; |
334 | } | 458 | } |
459 | else | ||
460 | { | ||
461 | FPRINTF (stderr, "%s", "\n"); | ||
462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n"); | ||
463 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
464 | GNUNET_SCHEDULER_cancel (die_task); | ||
465 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
466 | } | ||
335 | if (n % 5000 == 0) | 467 | if (n % 5000 == 0) |
336 | { | 468 | { |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 469 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
338 | "Returning total message block of size %u\n", ret); | 470 | "Returning total message block of size %u\n", ret); |
339 | } | 471 | } |
340 | total_bytes += ret; | 472 | total_bytes += ret; |
341 | if (n == TOTAL_MSGS) | ||
342 | { | ||
343 | FPRINTF (stderr, "%s", "\n"); | ||
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages sent\n"); | ||
345 | } | ||
346 | return ret; | 473 | return ret; |
347 | } | 474 | } |
348 | 475 | ||
@@ -350,31 +477,27 @@ notify_ready (void *cls, size_t size, void *buf) | |||
350 | static void | 477 | static void |
351 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 478 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) |
352 | { | 479 | { |
353 | 480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", | |
354 | struct PeerContext *p = cls; | 481 | GNUNET_i2s (peer), cls); |
355 | |||
356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n", | ||
357 | p->no, GNUNET_i2s (peer)); | ||
358 | } | 482 | } |
359 | 483 | ||
360 | 484 | ||
361 | static void | 485 | static void |
362 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 486 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
363 | { | 487 | { |
364 | struct PeerContext *p = cls; | 488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n", |
365 | 489 | GNUNET_i2s (peer), cls); | |
366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no, | ||
367 | GNUNET_i2s (peer)); | ||
368 | if (th != NULL) | 490 | if (th != NULL) |
369 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 491 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
370 | th = NULL; | 492 | th = NULL; |
371 | |||
372 | } | 493 | } |
373 | 494 | ||
374 | static void | 495 | static void |
375 | sendtask () | 496 | sendtask () |
376 | { | 497 | { |
377 | start_time = GNUNET_TIME_absolute_get (); | 498 | start_time = GNUNET_TIME_absolute_get (); |
499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to send %u messages\n", | ||
500 | TOTAL_MSGS); | ||
378 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), | 501 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), |
379 | TIMEOUT_TRANSMIT, ¬ify_ready, | 502 | TIMEOUT_TRANSMIT, ¬ify_ready, |
380 | NULL); | 503 | NULL); |
@@ -385,22 +508,20 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | |||
385 | { | 508 | { |
386 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 509 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); |
387 | 510 | ||
388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", | 511 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c, |
389 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | 512 | GNUNET_i2s (&p2->id)); |
390 | GNUNET_free (p1_c); | 513 | GNUNET_free (p1_c); |
391 | 514 | ||
392 | test_connected = GNUNET_YES; | 515 | test_connected = GNUNET_YES; |
393 | cc = NULL; | 516 | cc = NULL; |
394 | 517 | ||
395 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); | 518 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); |
396 | |||
397 | } | 519 | } |
398 | 520 | ||
399 | void | 521 | static void |
400 | start_cb (struct PeerContext *p, void *cls) | 522 | start_cb (struct PeerContext *p, void *cls) |
401 | { | 523 | { |
402 | static int started; | 524 | static int started; |
403 | |||
404 | started++; | 525 | started++; |
405 | 526 | ||
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | 527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, |
@@ -410,35 +531,17 @@ start_cb (struct PeerContext *p, void *cls) | |||
410 | return; | 531 | return; |
411 | 532 | ||
412 | test_connected = GNUNET_NO; | 533 | test_connected = GNUNET_NO; |
413 | |||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
415 | "Peer %u: `%s' using configuration file `%s'\n", p1->no, | ||
416 | GNUNET_i2s (&p1->id), cfg_file_p1); | ||
417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
418 | "Peer %u: `%s' using configuration file `%s'\n", p2->no, | ||
419 | GNUNET_i2s (&p2->id), cfg_file_p2); | ||
420 | |||
421 | sender = p2; | ||
422 | receiver = p1; | ||
423 | |||
424 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id)); | ||
425 | |||
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
427 | "Test triest to send from %u (%s) -> peer %u (%s)\n", sender->no, | ||
428 | sender_c, receiver->no, GNUNET_i2s (&receiver->id)); | ||
429 | GNUNET_free (sender_c); | ||
430 | |||
431 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, | 534 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, |
432 | NULL); | 535 | NULL); |
433 | 536 | ||
434 | } | 537 | } |
435 | 538 | ||
436 | |||
437 | static void | 539 | static void |
438 | run (void *cls, char *const *args, const char *cfgfile, | 540 | run (void *cls, char *const *args, const char *cfgfile, |
439 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 541 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
440 | { | 542 | { |
441 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 543 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
544 | test_send_timeout = GNUNET_NO; | ||
442 | 545 | ||
443 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | 546 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, |
444 | ¬ify_receive, ¬ify_connect, | 547 | ¬ify_receive, ¬ify_connect, |
@@ -448,21 +551,24 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
448 | ¬ify_receive, ¬ify_connect, | 551 | ¬ify_receive, ¬ify_connect, |
449 | ¬ify_disconnect, &start_cb, | 552 | ¬ify_disconnect, &start_cb, |
450 | NULL); | 553 | NULL); |
451 | |||
452 | if ((p1 == NULL) || (p2 == NULL)) | 554 | if ((p1 == NULL) || (p2 == NULL)) |
453 | { | 555 | { |
454 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | 556 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); |
455 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 557 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
456 | GNUNET_SCHEDULER_cancel (die_task); | 558 | GNUNET_SCHEDULER_cancel (die_task); |
457 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 559 | //die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
458 | return; | 560 | return; |
459 | } | 561 | } |
460 | } | 562 | } |
461 | 563 | ||
462 | static int | 564 | |
463 | check () | 565 | int |
566 | main (int argc, char *argv[]) | ||
464 | { | 567 | { |
465 | static char *argv[] = { "test_transport", | 568 | char *test_source; |
569 | int ret; | ||
570 | |||
571 | static char *const argv_new[] = { "test-transport-api-reliability", | ||
466 | "-c", | 572 | "-c", |
467 | "test_transport_api_data.conf", | 573 | "test_transport_api_data.conf", |
468 | NULL | 574 | NULL |
@@ -471,18 +577,6 @@ check () | |||
471 | GNUNET_GETOPT_OPTION_END | 577 | GNUNET_GETOPT_OPTION_END |
472 | }; | 578 | }; |
473 | 579 | ||
474 | ok = 1; | ||
475 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | ||
476 | "nohelp", options, &run, &ok); | ||
477 | |||
478 | return ok; | ||
479 | } | ||
480 | |||
481 | int | ||
482 | main (int argc, char *argv[]) | ||
483 | { | ||
484 | int ret; | ||
485 | |||
486 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); | 580 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); |
487 | 581 | ||
488 | GNUNET_log_setup (test_name, | 582 | GNUNET_log_setup (test_name, |
@@ -498,7 +592,17 @@ main (int argc, char *argv[]) | |||
498 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); | 592 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); |
499 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); | 593 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); |
500 | 594 | ||
501 | ret = check (); | 595 | |
596 | |||
597 | #if WRITECONFIG | ||
598 | setTransportOptions ("test_transport_api_data.conf"); | ||
599 | #endif | ||
600 | ok = GNUNET_SYSERR; | ||
601 | |||
602 | ret = GNUNET_PROGRAM_run ((sizeof (argv_new) / sizeof (char *)) - 1, argv_new, test_name, | ||
603 | "nohelp", options, &run, &ok); | ||
604 | if (GNUNET_SYSERR == ret) | ||
605 | ok = -1; | ||
502 | 606 | ||
503 | GNUNET_free (cfg_file_p1); | 607 | GNUNET_free (cfg_file_p1); |
504 | GNUNET_free (cfg_file_p2); | 608 | GNUNET_free (cfg_file_p2); |
@@ -507,8 +611,7 @@ main (int argc, char *argv[]) | |||
507 | GNUNET_free (test_plugin); | 611 | GNUNET_free (test_plugin); |
508 | GNUNET_free (test_name); | 612 | GNUNET_free (test_name); |
509 | 613 | ||
510 | return ret; | 614 | return ok; |
511 | } | 615 | } |
512 | 616 | ||
513 | |||
514 | /* end of test_transport_api_reliability.c */ | 617 | /* end of test_transport_api_reliability.c */ |
diff --git a/src/transport/test_transport_api_unreliability_udp_peer1.conf b/src/transport/test_transport_api_reliability_udp_peer1.conf index d16be3b20..d16be3b20 100644 --- a/src/transport/test_transport_api_unreliability_udp_peer1.conf +++ b/src/transport/test_transport_api_reliability_udp_peer1.conf | |||
diff --git a/src/transport/test_transport_api_unreliability_udp_peer2.conf b/src/transport/test_transport_api_reliability_udp_peer2.conf index a7e6a57fb..a7e6a57fb 100644 --- a/src/transport/test_transport_api_unreliability_udp_peer2.conf +++ b/src/transport/test_transport_api_reliability_udp_peer2.conf | |||
diff --git a/src/transport/test_transport_api_unreliability_unix_peer1.conf b/src/transport/test_transport_api_reliability_unix_peer1.conf index d43ef4a33..d43ef4a33 100644 --- a/src/transport/test_transport_api_unreliability_unix_peer1.conf +++ b/src/transport/test_transport_api_reliability_unix_peer1.conf | |||
diff --git a/src/transport/test_transport_api_unreliability_unix_peer2.conf b/src/transport/test_transport_api_reliability_unix_peer2.conf index f863d4d42..f863d4d42 100644 --- a/src/transport/test_transport_api_unreliability_unix_peer2.conf +++ b/src/transport/test_transport_api_reliability_unix_peer2.conf | |||
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c deleted file mode 100644 index 3f40a7179..000000000 --- a/src/transport/test_transport_api_unreliability.c +++ /dev/null | |||
@@ -1,588 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2010 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file transport/test_transport_api_unreliability.c | ||
22 | * @brief test case for transports; ensures messages get | ||
23 | * through, regardless of order | ||
24 | * | ||
25 | * This test case serves as a base for unreliable | ||
26 | * transport test cases to check that the transports | ||
27 | * achieve reliable message delivery. | ||
28 | */ | ||
29 | #include "platform.h" | ||
30 | #include "gnunet_transport_service.h" | ||
31 | #include "gauger.h" | ||
32 | #include "transport-testing.h" | ||
33 | |||
34 | /** | ||
35 | * Testcase timeout | ||
36 | */ | ||
37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900) | ||
38 | |||
39 | /** | ||
40 | * How long until we give up on transmitting the message? | ||
41 | */ | ||
42 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
43 | |||
44 | static char *test_source; | ||
45 | |||
46 | static char *test_plugin; | ||
47 | |||
48 | static char *test_name; | ||
49 | |||
50 | static int ok; | ||
51 | |||
52 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
53 | |||
54 | struct PeerContext *p1; | ||
55 | |||
56 | struct PeerContext *p2; | ||
57 | |||
58 | struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
59 | |||
60 | char *cfg_file_p1; | ||
61 | |||
62 | char *cfg_file_p2; | ||
63 | |||
64 | uint32_t max_bps_p1; | ||
65 | uint32_t max_bps_p2; | ||
66 | |||
67 | struct GNUNET_TRANSPORT_TESTING_handle *tth; | ||
68 | |||
69 | /* | ||
70 | * Testcase specific declarations | ||
71 | */ | ||
72 | |||
73 | /** | ||
74 | * Total number of messages to send | ||
75 | * | ||
76 | * Note that this value must not significantly exceed | ||
77 | * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise | ||
78 | * messages may be dropped even for a reliable transport. | ||
79 | */ | ||
80 | #define TOTAL_MSGS (1024 * 3) | ||
81 | |||
82 | #define MTYPE 12345 | ||
83 | |||
84 | GNUNET_NETWORK_STRUCT_BEGIN | ||
85 | |||
86 | struct TestMessage | ||
87 | { | ||
88 | struct GNUNET_MessageHeader header; | ||
89 | uint32_t num; | ||
90 | }; | ||
91 | GNUNET_NETWORK_STRUCT_END | ||
92 | |||
93 | static char *test_name; | ||
94 | |||
95 | static int msg_scheduled; | ||
96 | static int msg_sent; | ||
97 | static int msg_recv_expected; | ||
98 | static int msg_recv; | ||
99 | |||
100 | static int test_connected; | ||
101 | static int test_sending; | ||
102 | static int test_send_timeout; | ||
103 | |||
104 | static unsigned long long total_bytes; | ||
105 | |||
106 | static struct GNUNET_TIME_Absolute start_time; | ||
107 | |||
108 | static char bitmap[TOTAL_MSGS / 8]; | ||
109 | |||
110 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
111 | |||
112 | /* | ||
113 | * END Testcase specific declarations | ||
114 | */ | ||
115 | |||
116 | #if VERBOSE | ||
117 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | ||
118 | #else | ||
119 | #define OKPP do { ok++; } while (0) | ||
120 | #endif | ||
121 | |||
122 | static int | ||
123 | get_bit (const char *map, unsigned int bit); | ||
124 | |||
125 | static void | ||
126 | end () | ||
127 | { | ||
128 | unsigned long long delta; | ||
129 | unsigned long long rate; | ||
130 | char *value_name; | ||
131 | |||
132 | |||
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
134 | |||
135 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | ||
136 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); | ||
137 | FPRINTF (stderr, "\nThroughput was %llu KiBytes/s\n", | ||
138 | rate); | ||
139 | |||
140 | GNUNET_asprintf (&value_name, "unreliable_%s", test_plugin); | ||
141 | GAUGER ("TRANSPORT", value_name, (int) rate, | ||
142 | "kb/s"); | ||
143 | GNUNET_free (value_name); | ||
144 | |||
145 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
146 | GNUNET_SCHEDULER_cancel (die_task); | ||
147 | |||
148 | if (th != NULL) | ||
149 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
150 | th = NULL; | ||
151 | |||
152 | if (cc != NULL) | ||
153 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | ||
154 | cc = NULL; | ||
155 | |||
156 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | ||
157 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | ||
158 | |||
159 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
160 | |||
161 | ok = 0; | ||
162 | |||
163 | int i; | ||
164 | |||
165 | for (i = 0; i < TOTAL_MSGS; i++) | ||
166 | { | ||
167 | if (get_bit (bitmap, i) == 0) | ||
168 | { | ||
169 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); | ||
170 | ok = -1; | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 | |||
175 | static void | ||
176 | end_badly () | ||
177 | { | ||
178 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | ||
180 | |||
181 | if (test_connected == GNUNET_YES) | ||
182 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got connected\n"); | ||
183 | else | ||
184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); | ||
185 | |||
186 | if (test_sending == GNUNET_NO) | ||
187 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
188 | "Testcase did not send any messages before timeout\n"); | ||
189 | else | ||
190 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
191 | "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n", | ||
192 | msg_sent, msg_scheduled, msg_recv, msg_recv_expected); | ||
193 | if (test_send_timeout == GNUNET_YES) | ||
194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
195 | "Test had timeout while waiting to send data\n"); | ||
196 | |||
197 | int i; | ||
198 | |||
199 | for (i = 0; i < TOTAL_MSGS; i++) | ||
200 | { | ||
201 | if (get_bit (bitmap, i) == 0) | ||
202 | { | ||
203 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); | ||
204 | ok = -1; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | if (th != NULL) | ||
209 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
210 | th = NULL; | ||
211 | |||
212 | if (cc != NULL) | ||
213 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | ||
214 | cc = NULL; | ||
215 | |||
216 | if (p1 != NULL) | ||
217 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | ||
218 | if (p2 != NULL) | ||
219 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | ||
220 | |||
221 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
222 | |||
223 | ok = GNUNET_SYSERR; | ||
224 | } | ||
225 | |||
226 | |||
227 | static unsigned int | ||
228 | get_size (unsigned int iter) | ||
229 | { | ||
230 | unsigned int ret; | ||
231 | |||
232 | ret = (iter * iter * iter); | ||
233 | |||
234 | #ifndef LINUX | ||
235 | /* FreeBSD/OSX etc. Unix DGRAMs do not work | ||
236 | * with large messages */ | ||
237 | if (0 == strcmp ("unix", test_plugin)) | ||
238 | return sizeof (struct TestMessage) + (ret % 1024); | ||
239 | #endif | ||
240 | return sizeof (struct TestMessage) + (ret % 60000); | ||
241 | } | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Sets a bit active in the bitmap. | ||
246 | * | ||
247 | * @param bitIdx which bit to set | ||
248 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | ||
249 | */ | ||
250 | static int | ||
251 | set_bit (unsigned int bitIdx) | ||
252 | { | ||
253 | size_t arraySlot; | ||
254 | unsigned int targetBit; | ||
255 | |||
256 | if (bitIdx >= sizeof (bitmap) * 8) | ||
257 | { | ||
258 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "tried to set bit %d of %d(!?!?)\n", | ||
259 | bitIdx, sizeof (bitmap) * 8); | ||
260 | return GNUNET_SYSERR; | ||
261 | } | ||
262 | arraySlot = bitIdx / 8; | ||
263 | targetBit = (1L << (bitIdx % 8)); | ||
264 | bitmap[arraySlot] |= targetBit; | ||
265 | return GNUNET_OK; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * Obtain a bit from bitmap. | ||
270 | * @param map the bitmap | ||
271 | * @param bit index from bitmap | ||
272 | * | ||
273 | * @return Bit \a bit from hashcode \a code | ||
274 | */ | ||
275 | static int | ||
276 | get_bit (const char *map, unsigned int bit) | ||
277 | { | ||
278 | if (bit > TOTAL_MSGS) | ||
279 | { | ||
280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit, | ||
281 | sizeof (bitmap) * 8); | ||
282 | return 0; | ||
283 | } | ||
284 | return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; | ||
285 | } | ||
286 | |||
287 | |||
288 | static void | ||
289 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
290 | const struct GNUNET_MessageHeader *message) | ||
291 | { | ||
292 | static int n; | ||
293 | |||
294 | unsigned int s; | ||
295 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | ||
296 | const struct TestMessage *hdr; | ||
297 | |||
298 | hdr = (const struct TestMessage *) message; | ||
299 | |||
300 | if (MTYPE != ntohs (message->type)) | ||
301 | return; | ||
302 | msg_recv_expected = n; | ||
303 | msg_recv = ntohl (hdr->num); | ||
304 | s = get_size (ntohl (hdr->num)); | ||
305 | |||
306 | if (ntohs (message->size) != s) | ||
307 | { | ||
308 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
309 | "Expected message %u of size %u, got %u bytes of message %u\n", | ||
310 | ntohl (hdr->num), s, ntohs (message->size), ntohl (hdr->num)); | ||
311 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
312 | GNUNET_SCHEDULER_cancel (die_task); | ||
313 | test_sending = GNUNET_YES; | ||
314 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
315 | return; | ||
316 | } | ||
317 | |||
318 | memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage)); | ||
319 | if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) | ||
320 | { | ||
321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
322 | "Expected message %u with bits %u, but body did not match\n", | ||
323 | ntohl (hdr->num), (unsigned char) n); | ||
324 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
325 | GNUNET_SCHEDULER_cancel (die_task); | ||
326 | test_sending = GNUNET_YES; | ||
327 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
328 | return; | ||
329 | } | ||
330 | #if VERBOSE | ||
331 | if (ntohl (hdr->num) % 5 == 0) | ||
332 | { | ||
333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n", | ||
334 | ntohl (hdr->num), ntohs (message->size)); | ||
335 | } | ||
336 | #endif | ||
337 | n++; | ||
338 | if (GNUNET_SYSERR == set_bit (ntohl (hdr->num))) | ||
339 | { | ||
340 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
341 | _("Message id %u is bigger than maxmimum number of messages %u expected\n"), | ||
342 | ntohl (hdr->num), TOTAL_MSGS); | ||
343 | } | ||
344 | test_sending = GNUNET_YES; | ||
345 | if (0 == (n % (TOTAL_MSGS / 100))) | ||
346 | { | ||
347 | FPRINTF (stderr, "%s", "."); | ||
348 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
349 | GNUNET_SCHEDULER_cancel (die_task); | ||
350 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
351 | } | ||
352 | if (n == TOTAL_MSGS) | ||
353 | { | ||
354 | end (); | ||
355 | } | ||
356 | } | ||
357 | |||
358 | |||
359 | static size_t | ||
360 | notify_ready (void *cls, size_t size, void *buf) | ||
361 | { | ||
362 | static int n; | ||
363 | char *cbuf = buf; | ||
364 | struct TestMessage hdr; | ||
365 | unsigned int s; | ||
366 | unsigned int ret; | ||
367 | |||
368 | th = NULL; | ||
369 | |||
370 | if (buf == NULL) | ||
371 | { | ||
372 | test_send_timeout = GNUNET_YES; | ||
373 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
374 | "Timeout occurred while waiting for transmit_ready for msg %u of %u\n", | ||
375 | msg_scheduled, TOTAL_MSGS); | ||
376 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
377 | GNUNET_SCHEDULER_cancel (die_task); | ||
378 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
379 | ok = 42; | ||
380 | return 0; | ||
381 | } | ||
382 | ret = 0; | ||
383 | s = get_size (n); | ||
384 | GNUNET_assert (size >= s); | ||
385 | GNUNET_assert (buf != NULL); | ||
386 | GNUNET_assert (n < TOTAL_MSGS); | ||
387 | cbuf = buf; | ||
388 | do | ||
389 | { | ||
390 | GNUNET_assert (n < TOTAL_MSGS); | ||
391 | hdr.header.size = htons (s); | ||
392 | hdr.header.type = htons (MTYPE); | ||
393 | hdr.num = htonl (n); | ||
394 | msg_sent = n; | ||
395 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | ||
396 | ret += sizeof (struct TestMessage); | ||
397 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); | ||
398 | ret += s - sizeof (struct TestMessage); | ||
399 | |||
400 | #if VERBOSE | ||
401 | if (n % 5000 == 0) | ||
402 | { | ||
403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n, | ||
404 | s); | ||
405 | } | ||
406 | #endif | ||
407 | n++; | ||
408 | s = get_size (n); | ||
409 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | ||
410 | break; /* sometimes pack buffer full, sometimes not */ | ||
411 | } | ||
412 | while ((size - ret >= s) && (n < TOTAL_MSGS)); | ||
413 | if (n < TOTAL_MSGS) | ||
414 | { | ||
415 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, | ||
416 | TIMEOUT_TRANSMIT, | ||
417 | ¬ify_ready, NULL); | ||
418 | msg_scheduled = n; | ||
419 | } | ||
420 | else | ||
421 | { | ||
422 | FPRINTF (stderr, "%s", "\n"); | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n"); | ||
424 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
425 | GNUNET_SCHEDULER_cancel (die_task); | ||
426 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
427 | } | ||
428 | if (n % 5000 == 0) | ||
429 | { | ||
430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
431 | "Returning total message block of size %u\n", ret); | ||
432 | } | ||
433 | total_bytes += ret; | ||
434 | return ret; | ||
435 | } | ||
436 | |||
437 | |||
438 | static void | ||
439 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
440 | { | ||
441 | |||
442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", | ||
443 | GNUNET_i2s (peer), cls); | ||
444 | } | ||
445 | |||
446 | |||
447 | static void | ||
448 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
449 | { | ||
450 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n", | ||
451 | GNUNET_i2s (peer), cls); | ||
452 | if (th != NULL) | ||
453 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
454 | th = NULL; | ||
455 | } | ||
456 | |||
457 | static void | ||
458 | sendtask () | ||
459 | { | ||
460 | start_time = GNUNET_TIME_absolute_get (); | ||
461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to send %u messages\n", | ||
462 | TOTAL_MSGS); | ||
463 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), | ||
464 | TIMEOUT_TRANSMIT, ¬ify_ready, | ||
465 | NULL); | ||
466 | } | ||
467 | |||
468 | static void | ||
469 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | ||
470 | { | ||
471 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
472 | |||
473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c, | ||
474 | GNUNET_i2s (&p2->id)); | ||
475 | GNUNET_free (p1_c); | ||
476 | |||
477 | test_connected = GNUNET_YES; | ||
478 | cc = NULL; | ||
479 | |||
480 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
481 | } | ||
482 | |||
483 | void | ||
484 | start_cb (struct PeerContext *p, void *cls) | ||
485 | { | ||
486 | static int started; | ||
487 | |||
488 | started++; | ||
489 | |||
490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | ||
491 | GNUNET_i2s (&p->id)); | ||
492 | |||
493 | if (started != 2) | ||
494 | return; | ||
495 | |||
496 | test_connected = GNUNET_NO; | ||
497 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, | ||
498 | NULL); | ||
499 | |||
500 | } | ||
501 | |||
502 | static void | ||
503 | run (void *cls, char *const *args, const char *cfgfile, | ||
504 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
505 | { | ||
506 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
507 | test_send_timeout = GNUNET_NO; | ||
508 | |||
509 | |||
510 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | ||
511 | ¬ify_receive, ¬ify_connect, | ||
512 | ¬ify_disconnect, &start_cb, | ||
513 | NULL); | ||
514 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | ||
515 | ¬ify_receive, ¬ify_connect, | ||
516 | ¬ify_disconnect, &start_cb, | ||
517 | NULL); | ||
518 | |||
519 | |||
520 | if ((p1 == NULL) || (p2 == NULL)) | ||
521 | { | ||
522 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
523 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
524 | GNUNET_SCHEDULER_cancel (die_task); | ||
525 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
526 | return; | ||
527 | } | ||
528 | |||
529 | |||
530 | } | ||
531 | |||
532 | static int | ||
533 | check () | ||
534 | { | ||
535 | static char *const argv[] = { "test-transport-api-unreliability", | ||
536 | "-c", | ||
537 | "test_transport_api_data.conf", | ||
538 | NULL | ||
539 | }; | ||
540 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
541 | GNUNET_GETOPT_OPTION_END | ||
542 | }; | ||
543 | |||
544 | #if WRITECONFIG | ||
545 | setTransportOptions ("test_transport_api_data.conf"); | ||
546 | #endif | ||
547 | ok = GNUNET_SYSERR; | ||
548 | |||
549 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | ||
550 | "nohelp", options, &run, &ok); | ||
551 | |||
552 | return ok; | ||
553 | } | ||
554 | |||
555 | int | ||
556 | main (int argc, char *argv[]) | ||
557 | { | ||
558 | int ret; | ||
559 | |||
560 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); | ||
561 | |||
562 | GNUNET_log_setup (test_name, | ||
563 | "WARNING", | ||
564 | NULL); | ||
565 | |||
566 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); | ||
567 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, | ||
568 | &test_plugin); | ||
569 | |||
570 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
571 | |||
572 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); | ||
573 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); | ||
574 | |||
575 | ret = check (); | ||
576 | |||
577 | GNUNET_free (cfg_file_p1); | ||
578 | GNUNET_free (cfg_file_p2); | ||
579 | |||
580 | GNUNET_free (test_source); | ||
581 | GNUNET_free (test_plugin); | ||
582 | GNUNET_free (test_name); | ||
583 | |||
584 | |||
585 | return ret; | ||
586 | } | ||
587 | |||
588 | /* end of test_transport_api_unreliability.c */ | ||