diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-17 10:05:51 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-17 10:05:51 +0000 |
commit | 7a869109cf7b6e58af7cccc5ef2bcfa9b84d4fc8 (patch) | |
tree | 9f13a834d0661253edcef88b7b2114c422976d7c /src/transport/test_quota_compliance.c | |
parent | 31ab92e674ff6892e4ee6b0736164094f14c3a0a (diff) | |
download | gnunet-7a869109cf7b6e58af7cccc5ef2bcfa9b84d4fc8.tar.gz gnunet-7a869109cf7b6e58af7cccc5ef2bcfa9b84d4fc8.zip |
new quota compliance
Diffstat (limited to 'src/transport/test_quota_compliance.c')
-rw-r--r-- | src/transport/test_quota_compliance.c | 1139 |
1 files changed, 408 insertions, 731 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index f73fea237..d8e5c3f44 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "gnunet_scheduler_lib.h" | 32 | #include "gnunet_scheduler_lib.h" |
33 | #include "gnunet_server_lib.h" | 33 | #include "gnunet_server_lib.h" |
34 | #include "gnunet_transport_service.h" | 34 | #include "gnunet_transport_service.h" |
35 | #include "gauger.h" | ||
35 | #include "transport.h" | 36 | #include "transport.h" |
36 | #include "transport-testing.h" | 37 | #include "transport-testing.h" |
37 | 38 | ||
@@ -40,897 +41,573 @@ | |||
40 | #define VERBOSE_ARM GNUNET_EXTRA_LOGGING | 41 | #define VERBOSE_ARM GNUNET_EXTRA_LOGGING |
41 | 42 | ||
42 | #define START_ARM GNUNET_YES | 43 | #define START_ARM GNUNET_YES |
43 | #define DEBUG_MEASUREMENT GNUNET_EXTRA_LOGGING | ||
44 | #define DEBUG_CONNECTIONS GNUNET_EXTRA_LOGGING | ||
45 | |||
46 | #define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
47 | #define MEASUREMENT_MSG_SIZE 1024 | ||
48 | #define MEASUREMENT_MSG_SIZE_BIG 32768 | ||
49 | #define MEASUREMENT_MAX_QUOTA 1024 * 1024 * 1024 | ||
50 | #define MEASUREMENT_MIN_QUOTA 1024 | ||
51 | #define SEND_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
52 | #define MEASUREMENT_SOFT_LIMIT 1024 | ||
53 | 44 | ||
54 | /** | 45 | /** |
55 | * Testcase timeout | 46 | * Testcase timeout |
56 | */ | 47 | */ |
57 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 200) | 48 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
58 | |||
59 | |||
60 | |||
61 | #define MTYPE 11111 | ||
62 | 49 | ||
63 | /** | 50 | /** |
64 | * Handle for a transmission-ready request. | 51 | * How long until we give up on transmitting the message? |
65 | */ | 52 | */ |
66 | struct GNUNET_TRANSPORT_TransmitHandle | 53 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) |
67 | { | ||
68 | 54 | ||
69 | /** | 55 | #define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
70 | * Neighbour for this handle, NULL for control-traffic. | ||
71 | */ | ||
72 | struct NeighbourList *neighbour; | ||
73 | |||
74 | /** | ||
75 | * Function to call when notify_size bytes are available | ||
76 | * for transmission. | ||
77 | */ | ||
78 | GNUNET_CONNECTION_TransmitReadyNotify notify; | ||
79 | |||
80 | /** | ||
81 | * Closure for notify. | ||
82 | */ | ||
83 | void *notify_cls; | ||
84 | |||
85 | /** | ||
86 | * transmit_ready task Id. The task is used to introduce the | ||
87 | * artificial delay that may be required to maintain the bandwidth | ||
88 | * limits. Later, this will be the ID of the "transmit_timeout" | ||
89 | * task which is used to signal a timeout if the transmission could | ||
90 | * not be done in a timely fashion. | ||
91 | */ | ||
92 | GNUNET_SCHEDULER_TaskIdentifier notify_delay_task; | ||
93 | |||
94 | /** | ||
95 | * Timeout for this request. | ||
96 | */ | ||
97 | struct GNUNET_TIME_Absolute timeout; | ||
98 | |||
99 | /** | ||
100 | * How many bytes is our notify callback waiting for? | ||
101 | */ | ||
102 | size_t notify_size; | ||
103 | |||
104 | /** | ||
105 | * How important is this message? | ||
106 | */ | ||
107 | unsigned int priority; | ||
108 | 56 | ||
109 | }; | 57 | static char *test_source; |
110 | 58 | ||
111 | static struct PeerContext p1; | 59 | static char *test_plugin; |
112 | 60 | ||
113 | static struct PeerContext p2; | 61 | static char *test_name; |
114 | 62 | ||
115 | static int ok; | 63 | static int ok; |
116 | 64 | ||
117 | static int connected; | 65 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
118 | static int measurement_running; | ||
119 | static int send_running; | ||
120 | static int recv_running; | ||
121 | 66 | ||
122 | static unsigned long long total_bytes_sent; | 67 | static GNUNET_SCHEDULER_TaskIdentifier measure_task; |
123 | static unsigned long long last_msg_sent; | ||
124 | static unsigned long long last_msg_recv; | ||
125 | static unsigned long long current_quota_p1; | ||
126 | static unsigned long long current_quota_p2; | ||
127 | |||
128 | static int is_tcp; | ||
129 | static int is_tcp_nat; | ||
130 | static int is_http; | ||
131 | static int is_https; | ||
132 | static int is_udp; | ||
133 | static int is_unix; | ||
134 | static int is_asymmetric_send_constant; | ||
135 | static int is_asymmetric_recv_constant; | ||
136 | 68 | ||
137 | static struct GNUNET_TIME_Absolute start_time; | 69 | struct PeerContext *p1; |
138 | 70 | ||
139 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 71 | struct PeerContext *p2; |
140 | static GNUNET_SCHEDULER_TaskIdentifier tct; | ||
141 | static GNUNET_SCHEDULER_TaskIdentifier measurement_task; | ||
142 | static GNUNET_SCHEDULER_TaskIdentifier measurement_counter_task; | ||
143 | 72 | ||
144 | static struct GNUNET_TRANSPORT_TransmitHandle *transmit_handle; | 73 | struct PeerContext * sender; |
145 | 74 | ||
146 | #define OKPP do { ok++; } while (0) | 75 | struct PeerContext * receiver; |
147 | 76 | ||
77 | struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
148 | 78 | ||
149 | static void | 79 | char *cfg_file_p1; |
150 | end () | 80 | char *gen_cfg_p2; |
151 | { | 81 | unsigned long long quota_in_p1; |
152 | GNUNET_SCHEDULER_cancel (die_task); | 82 | unsigned long long quota_out_p1; |
153 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
154 | 83 | ||
155 | if (measurement_task != GNUNET_SCHEDULER_NO_TASK) | 84 | char *cfg_file_p2; |
156 | { | 85 | char *gen_cfg_p1; |
157 | GNUNET_SCHEDULER_cancel (measurement_task); | 86 | unsigned long long quota_in_p2; |
158 | measurement_task = GNUNET_SCHEDULER_NO_TASK; | 87 | unsigned long long quota_out_p2; |
159 | } | ||
160 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) | ||
161 | { | ||
162 | GNUNET_SCHEDULER_cancel (measurement_counter_task); | ||
163 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; | ||
164 | } | ||
165 | fprintf (stderr, "\n"); | ||
166 | GNUNET_SCHEDULER_shutdown (); | ||
167 | #if DEBUG_CONNECTIONS | ||
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | ||
169 | #endif | ||
170 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
171 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
172 | #if DEBUG_CONNECTIONS | ||
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
174 | "Transports disconnected, returning success!\n"); | ||
175 | #endif | ||
176 | GNUNET_SCHEDULER_shutdown (); | ||
177 | } | ||
178 | 88 | ||
89 | struct GNUNET_TRANSPORT_TESTING_handle * tth; | ||
179 | 90 | ||
91 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
180 | 92 | ||
181 | static void | 93 | /* |
182 | stop_arm (struct PeerContext *p) | 94 | * Testcase specific declarations |
95 | */ | ||
96 | |||
97 | /** | ||
98 | * Note that this value must not significantly exceed | ||
99 | * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise | ||
100 | * messages may be dropped even for a reliable transport. | ||
101 | */ | ||
102 | #define TOTAL_MSGS (1024 * 2) | ||
103 | |||
104 | #define MTYPE 12345 | ||
105 | |||
106 | struct TestMessage | ||
183 | { | 107 | { |
184 | #if START_ARM | 108 | struct GNUNET_MessageHeader header; |
185 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 109 | uint32_t num; |
186 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 110 | }; |
187 | GNUNET_OS_process_wait (p->arm_proc); | 111 | |
188 | GNUNET_OS_process_close (p->arm_proc); | 112 | static int msg_scheduled; |
189 | p->arm_proc = NULL; | 113 | static int msg_sent; |
114 | static int msg_recv_expected; | ||
115 | static int msg_recv; | ||
116 | |||
117 | static int test_failed; | ||
118 | static int test_connected; | ||
119 | |||
120 | static unsigned long long total_bytes_sent; | ||
121 | |||
122 | static struct GNUNET_TIME_Absolute start_time; | ||
123 | |||
124 | /* | ||
125 | * END Testcase specific declarations | ||
126 | */ | ||
127 | |||
128 | #if VERBOSE | ||
129 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | ||
130 | #else | ||
131 | #define OKPP do { ok++; } while (0) | ||
190 | #endif | 132 | #endif |
191 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
192 | } | ||
193 | 133 | ||
194 | 134 | ||
195 | static void | 135 | static void |
196 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 136 | end () |
197 | { | 137 | { |
198 | if (measurement_task != GNUNET_SCHEDULER_NO_TASK) | 138 | unsigned long long delta; |
139 | unsigned long long datarate; | ||
140 | |||
141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
142 | |||
143 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; | ||
144 | datarate = (total_bytes_sent * 1000) / delta; | ||
145 | |||
146 | fprintf (stderr, "\nThroughput was %llu b/s\n", | ||
147 | datarate); | ||
148 | |||
149 | test_failed = GNUNET_NO; | ||
150 | if (datarate > quota_in_p2) | ||
199 | { | 151 | { |
200 | GNUNET_SCHEDULER_cancel (measurement_task); | 152 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
201 | measurement_task = GNUNET_SCHEDULER_NO_TASK; | 153 | "Datarate of %llu higher than allowed inbound quota of %llu\n", datarate, quota_in_p2); |
154 | test_failed = GNUNET_YES; | ||
202 | } | 155 | } |
203 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) | 156 | if (datarate > quota_out_p1) |
204 | { | 157 | { |
205 | GNUNET_SCHEDULER_cancel (measurement_counter_task); | 158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
206 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; | 159 | "Datarate of %llu higher than allowed outbound quota of %llu\n", datarate, quota_out_p1); |
160 | test_failed = GNUNET_YES; | ||
207 | } | 161 | } |
208 | GNUNET_break (0); | 162 | if (test_failed == GNUNET_NO) |
209 | if (GNUNET_SCHEDULER_NO_TASK != tct) | ||
210 | { | 163 | { |
211 | GNUNET_SCHEDULER_cancel (tct); | 164 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
212 | tct = GNUNET_SCHEDULER_NO_TASK; | 165 | "Datarate of %llu complied to allowed outbound quota of %llu and inbound quota of %llu\n", datarate, quota_out_p1, quota_in_p2); |
213 | } | 166 | } |
214 | if (p1.th != NULL) | 167 | |
215 | GNUNET_TRANSPORT_disconnect (p1.th); | 168 | |
216 | if (p2.th != NULL) | 169 | |
217 | GNUNET_TRANSPORT_disconnect (p2.th); | 170 | |
218 | ok = 1; | 171 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
172 | GNUNET_SCHEDULER_cancel (die_task); | ||
173 | |||
174 | if (th != NULL) | ||
175 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
176 | th = NULL; | ||
177 | |||
178 | if (cc != NULL) | ||
179 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); | ||
180 | |||
181 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | ||
182 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | ||
183 | |||
219 | } | 184 | } |
220 | 185 | ||
221 | struct TestMessage | 186 | static void |
187 | end_badly () | ||
222 | { | 188 | { |
223 | struct GNUNET_MessageHeader header; | 189 | die_task = GNUNET_SCHEDULER_NO_TASK; |
224 | uint32_t num; | 190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
225 | }; | 191 | |
192 | if (test_connected == GNUNET_YES) | ||
193 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got connected\n"); | ||
194 | else | ||
195 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); | ||
196 | |||
197 | if (th != NULL) | ||
198 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
199 | th = NULL; | ||
200 | |||
201 | if (cc != NULL) | ||
202 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); | ||
203 | |||
204 | if (p1 != NULL) | ||
205 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | ||
206 | if (p2 != NULL) | ||
207 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | ||
208 | |||
209 | ok = GNUNET_SYSERR; | ||
210 | } | ||
226 | 211 | ||
227 | 212 | ||
228 | static unsigned int | 213 | static unsigned int |
229 | get_size () | 214 | get_size (unsigned int iter) |
230 | { | 215 | { |
231 | return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage); | 216 | unsigned int ret; |
217 | |||
218 | ret = (iter * iter * iter); | ||
219 | return sizeof (struct TestMessage) + (ret % 60000); | ||
232 | } | 220 | } |
233 | 221 | ||
222 | |||
234 | static void | 223 | static void |
235 | notify_receive_new (void *cls, const struct GNUNET_PeerIdentity *peer, | 224 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, |
236 | const struct GNUNET_MessageHeader *message, | 225 | const struct GNUNET_MessageHeader *message, |
237 | const struct GNUNET_ATS_Information *ats, | 226 | const struct GNUNET_ATS_Information *ats, |
238 | uint32_t ats_count) | 227 | uint32_t ats_count) |
239 | { | 228 | { |
229 | static int n; | ||
230 | unsigned int s; | ||
231 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | ||
240 | const struct TestMessage *hdr; | 232 | const struct TestMessage *hdr; |
241 | 233 | ||
242 | GNUNET_assert (message != NULL); | ||
243 | hdr = (const struct TestMessage *) message; | 234 | hdr = (const struct TestMessage *) message; |
244 | if (measurement_running == GNUNET_NO) | 235 | s = get_size (n); |
245 | return; | ||
246 | if (MTYPE != ntohs (message->type)) | 236 | if (MTYPE != ntohs (message->type)) |
247 | return; | 237 | return; |
248 | 238 | msg_recv_expected = n; | |
249 | #if DEBUG_MEASUREMENT | 239 | msg_recv = ntohl (hdr->num); |
240 | if (ntohs (message->size) != (s)) | ||
241 | { | ||
242 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
243 | "Expected message %u of size %u, got %u bytes of message %u\n", | ||
244 | n, s, ntohs (message->size), ntohl (hdr->num)); | ||
245 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
246 | GNUNET_SCHEDULER_cancel (die_task); | ||
247 | test_failed = GNUNET_YES; | ||
248 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
249 | return; | ||
250 | } | ||
251 | if (ntohl (hdr->num) != n) | ||
252 | { | ||
253 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
254 | "Expected message %u of size %u, got %u bytes of message %u\n", | ||
255 | n, s, ntohs (message->size), ntohl (hdr->num)); | ||
256 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
257 | GNUNET_SCHEDULER_cancel (die_task); | ||
258 | test_failed = GNUNET_YES; | ||
259 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
260 | return; | ||
261 | } | ||
262 | memset (cbuf, n, s - sizeof (struct TestMessage)); | ||
263 | if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) | ||
264 | { | ||
265 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
266 | "Expected message %u with bits %u, but body did not match\n", n, | ||
267 | (unsigned char) n); | ||
268 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
269 | GNUNET_SCHEDULER_cancel (die_task); | ||
270 | test_failed = GNUNET_YES; | ||
271 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
272 | return; | ||
273 | } | ||
274 | #if VERBOSE | ||
250 | if (ntohl (hdr->num) % 5000 == 0) | 275 | if (ntohl (hdr->num) % 5000 == 0) |
251 | { | 276 | { |
252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n", | 277 | struct PeerContext *p = cls; |
253 | ntohl (hdr->num), ntohs (message->size)); | 278 | char * ps = strdup(GNUNET_i2s(&p->id)); |
279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", | ||
280 | p->no, ps, ntohl (hdr->num), ntohs (message->size), GNUNET_i2s(peer)); | ||
281 | GNUNET_free (ps); | ||
254 | } | 282 | } |
255 | #endif | 283 | #endif |
256 | /* | 284 | n++; |
257 | * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 285 | if (0 == (n % (TOTAL_MSGS / 100))) |
258 | * "Got message %u\n", | 286 | { |
259 | * ntohl (hdr->num)); */ | 287 | fprintf (stderr, "."); |
260 | last_msg_recv = ntohl (hdr->num); | 288 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
289 | GNUNET_SCHEDULER_cancel (die_task); | ||
290 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
291 | } | ||
292 | if (n == TOTAL_MSGS) | ||
293 | { | ||
294 | ok = 0; | ||
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nAll messages received\n"); | ||
296 | end (); | ||
297 | } | ||
261 | } | 298 | } |
262 | 299 | ||
263 | 300 | ||
264 | static size_t | 301 | static size_t |
265 | notify_ready (void *cls, size_t size, void *buf) | 302 | notify_ready (void *cls, size_t size, void *buf) |
266 | { | 303 | { |
304 | static int n; | ||
267 | char *cbuf = buf; | 305 | char *cbuf = buf; |
268 | struct TestMessage hdr; | 306 | struct TestMessage hdr; |
269 | unsigned int s; | 307 | unsigned int s; |
270 | unsigned int ret; | 308 | unsigned int ret; |
271 | 309 | ||
272 | transmit_handle = NULL; | 310 | th = NULL; |
273 | if (measurement_task == GNUNET_SCHEDULER_NO_TASK) | ||
274 | return 0; | ||
275 | |||
276 | if (buf == NULL) | 311 | if (buf == NULL) |
277 | { | 312 | { |
313 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
314 | "Timeout occurred while waiting for transmit_ready for message %u of %u\n", msg_scheduled, TOTAL_MSGS); | ||
315 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
316 | GNUNET_SCHEDULER_cancel (die_task); | ||
317 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
278 | ok = 42; | 318 | ok = 42; |
279 | return 0; | 319 | return 0; |
280 | } | 320 | } |
281 | if (measurement_running != GNUNET_YES) | 321 | |
282 | { | ||
283 | send_running = GNUNET_NO; | ||
284 | return 0; | ||
285 | } | ||
286 | send_running = GNUNET_YES; | ||
287 | ret = 0; | 322 | ret = 0; |
288 | s = get_size (); | 323 | s = get_size (n); |
289 | GNUNET_assert (size >= s); | 324 | GNUNET_assert (size >= s); |
290 | GNUNET_assert (buf != NULL); | 325 | GNUNET_assert (buf != NULL); |
291 | last_msg_sent++; | ||
292 | cbuf = buf; | 326 | cbuf = buf; |
293 | do | 327 | do |
294 | { | 328 | { |
295 | hdr.header.size = htons (s); | 329 | hdr.header.size = htons (s); |
296 | hdr.header.type = htons (MTYPE); | 330 | hdr.header.type = htons (MTYPE); |
297 | hdr.num = htonl (last_msg_sent); | 331 | hdr.num = htonl (n); |
332 | msg_sent = n; | ||
298 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | 333 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); |
299 | ret += sizeof (struct TestMessage); | 334 | ret += sizeof (struct TestMessage); |
300 | memset (&cbuf[ret], last_msg_sent, s - sizeof (struct TestMessage)); | 335 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); |
301 | ret += s - sizeof (struct TestMessage); | 336 | ret += s - sizeof (struct TestMessage); |
302 | #if DEBUG_MEASUREMENT | 337 | #if VERBOSE |
303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u\n", last_msg_sent); | 338 | if (n % 5000 == 0) |
339 | { | ||
340 | |||
341 | char * receiver_s = strdup(GNUNET_i2s (&receiver->id)); | ||
342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
343 | "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
344 | n, | ||
345 | sender->no, | ||
346 | GNUNET_i2s (&sender->id), receiver->no, receiver_s); | ||
347 | GNUNET_free (receiver_s); | ||
348 | } | ||
304 | #endif | 349 | #endif |
305 | s = get_size (); | 350 | n++; |
351 | s = get_size (n); | ||
306 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 352 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
307 | break; /* sometimes pack buffer full, sometimes not */ | 353 | break; /* sometimes pack buffer full, sometimes not */ |
308 | } | 354 | } |
309 | while (size - ret >= s); | 355 | while (size - ret >= s); |
310 | transmit_handle = | 356 | if (n < TOTAL_MSGS) |
311 | GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, s, 0, SEND_TIMEOUT, | 357 | { |
312 | ¬ify_ready, NULL); | 358 | if (th == NULL) |
313 | total_bytes_sent += s; | 359 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, 0, |
360 | TIMEOUT_TRANSMIT, | ||
361 | ¬ify_ready, NULL); | ||
362 | msg_scheduled = n; | ||
363 | } | ||
364 | if (n % 5000 == 0) | ||
365 | { | ||
366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
367 | "Returning total message block of size %u\n", ret); | ||
368 | } | ||
369 | total_bytes_sent += ret; | ||
370 | if (n == TOTAL_MSGS) | ||
371 | { | ||
372 | fprintf (stderr, "\n"); | ||
373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages sent\n"); | ||
374 | } | ||
314 | return ret; | 375 | return ret; |
315 | } | 376 | } |
316 | 377 | ||
317 | 378 | ||
318 | static void | 379 | static void |
319 | measure (unsigned long long quota_p1, unsigned long long quota_p2); | 380 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
381 | const struct GNUNET_ATS_Information *ats, | ||
382 | uint32_t ats_count) | ||
383 | { | ||
384 | |||
385 | struct PeerContext *p = cls; | ||
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n", | ||
387 | p->no, GNUNET_i2s (peer)); | ||
388 | } | ||
389 | |||
320 | 390 | ||
321 | static void | 391 | static void |
322 | measurement_counter (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 392 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
323 | { | 393 | { |
324 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; | 394 | struct PeerContext *p = cls; |
325 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", |
326 | return; | 396 | p->no, GNUNET_i2s (peer)); |
397 | if (th != NULL) | ||
398 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
399 | th = NULL; | ||
327 | 400 | ||
328 | fprintf (stderr, "."); | ||
329 | measurement_counter_task = | ||
330 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
331 | &measurement_counter, NULL); | ||
332 | } | 401 | } |
333 | 402 | ||
403 | static void | ||
404 | sendtask () | ||
405 | { | ||
406 | start_time = GNUNET_TIME_absolute_get (); | ||
407 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), 0, | ||
408 | TIMEOUT_TRANSMIT, ¬ify_ready, | ||
409 | NULL); | ||
410 | } | ||
334 | 411 | ||
335 | static void | 412 | static void |
336 | measurement_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 413 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) |
337 | { | 414 | { |
338 | static int strike_counter; | 415 | char *p1_c = strdup (GNUNET_i2s (&p1->id)); |
339 | static int failed_measurement_counter = 1; | 416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", |
340 | unsigned long long quota_allowed = 0; | 417 | p1->no, p1_c, |
341 | int delta = 0; | 418 | p2->no, GNUNET_i2s (&p2->id)); |
419 | GNUNET_free (p1_c); | ||
342 | 420 | ||
343 | measurement_task = GNUNET_SCHEDULER_NO_TASK; | 421 | cc = NULL; |
344 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 422 | test_connected = GNUNET_YES; |
345 | return; | ||
346 | 423 | ||
347 | measurement_running = GNUNET_NO; | 424 | measure_task = GNUNET_SCHEDULER_add_delayed (DURATION, &end, NULL); |
348 | struct GNUNET_TIME_Relative duration = | 425 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); |
349 | GNUNET_TIME_absolute_get_difference (start_time, | ||
350 | GNUNET_TIME_absolute_get ()); | ||
351 | 426 | ||
427 | } | ||
352 | 428 | ||
353 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) | 429 | void start_cb (struct PeerContext * p, |
354 | { | 430 | void *cls) |
355 | GNUNET_SCHEDULER_cancel (measurement_counter_task); | 431 | { |
356 | measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; | 432 | static int started; |
357 | } | 433 | started++; |
358 | 434 | ||
359 | if (transmit_handle != NULL) | 435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", |
360 | { | 436 | p->no, |
361 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle); | 437 | GNUNET_i2s (&p->id)); |
362 | transmit_handle = NULL; | ||
363 | } | ||
364 | 438 | ||
365 | if (current_quota_p1 < current_quota_p2) | 439 | if (started != 2) |
366 | quota_allowed = current_quota_p1; | 440 | return; |
367 | else | ||
368 | quota_allowed = current_quota_p2; | ||
369 | 441 | ||
442 | test_connected = GNUNET_NO; | ||
370 | 443 | ||
371 | if (MEASUREMENT_SOFT_LIMIT > (quota_allowed / 3)) | 444 | sender = p2; |
372 | delta = MEASUREMENT_SOFT_LIMIT; | 445 | receiver = p1; |
373 | else | ||
374 | delta = (quota_allowed / 3); | ||
375 | 446 | ||
376 | /* Throughput is far too slow. This is to prevent the test to exit with success when throughput is 0 */ | 447 | char *sender_c = strdup (GNUNET_i2s (&sender->id)); |
377 | if ((total_bytes_sent / (duration.rel_value / 1000)) < 100) | 448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to send from %u (%s) -> peer %u (%s)\n", |
378 | { | 449 | sender->no, sender_c, |
379 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 450 | receiver->no, GNUNET_i2s (&receiver->id)); |
380 | "\nQuota compliance failed: \n" | ||
381 | "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n" | ||
382 | "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n" | ||
383 | "Throughput : %10llu kB/s (%llu B/s)\n", | ||
384 | (quota_allowed / (1024)), quota_allowed, | ||
385 | ((quota_allowed + delta) / (1024)), quota_allowed + delta, | ||
386 | (total_bytes_sent / (duration.rel_value / 1000) / 1024), | ||
387 | total_bytes_sent / (duration.rel_value / 1000)); | ||
388 | ok = 1; | ||
389 | failed_measurement_counter--; | ||
390 | if (failed_measurement_counter < 0) | ||
391 | { | ||
392 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
393 | "\nQuota measurement failed and no free strike: %i\n", | ||
394 | failed_measurement_counter); | ||
395 | end (); | ||
396 | return; | ||
397 | } | ||
398 | else | ||
399 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
400 | "\nQuota measurement failed and %i free strikes\n", | ||
401 | failed_measurement_counter); | ||
402 | } | ||
403 | 451 | ||
404 | /* Throughput is bigger than allowed quota + some extra */ | 452 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); |
405 | if ((total_bytes_sent / (duration.rel_value / 1000)) > | ||
406 | (quota_allowed + delta)) | ||
407 | { | ||
408 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
409 | "\nQuota compliance failed: \n" | ||
410 | "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n" | ||
411 | "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n" | ||
412 | "Throughput : %10llu kB/s (%llu B/s)\n", | ||
413 | (quota_allowed / (1024)), quota_allowed, | ||
414 | ((quota_allowed + delta) / (1024)), quota_allowed + delta, | ||
415 | (total_bytes_sent / (duration.rel_value / 1000) / 1024), | ||
416 | total_bytes_sent / (duration.rel_value / 1000)); | ||
417 | ok = 1; | ||
418 | failed_measurement_counter--; | ||
419 | if (failed_measurement_counter < 0) | ||
420 | { | ||
421 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
422 | "\nQuota measurement failed and no free strike: %i\n", | ||
423 | failed_measurement_counter); | ||
424 | end (); | ||
425 | return; | ||
426 | } | ||
427 | else | ||
428 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
429 | "\nQuota measurement failed and %i free strikes\n", | ||
430 | failed_measurement_counter); | ||
431 | } | ||
432 | else | ||
433 | { | ||
434 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
435 | "\nQuota compliance ok: \n" "Quota allowed: %10llu kB/s\n" | ||
436 | "Throughput : %10llu kB/s\n", (quota_allowed / (1024)), | ||
437 | (total_bytes_sent / (duration.rel_value / 1000) / 1024)); | ||
438 | if (failed_measurement_counter < 2) | ||
439 | failed_measurement_counter++; | ||
440 | ok = 0; | ||
441 | } | ||
442 | 453 | ||
443 | if ((quota_allowed) > (2 * (total_bytes_sent / (duration.rel_value / 1000)))) | ||
444 | { | ||
445 | if (failed_measurement_counter < 2) | ||
446 | failed_measurement_counter++; | ||
447 | if (strike_counter == 2) | ||
448 | { | ||
449 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
450 | "Maximum transmission rate reached, stopping test\n"); | ||
451 | end (); | ||
452 | return; | ||
453 | } | ||
454 | } | ||
455 | else | ||
456 | { | ||
457 | strike_counter = 0; | ||
458 | } | ||
459 | |||
460 | if (quota_allowed == MEASUREMENT_MAX_QUOTA) | ||
461 | { | ||
462 | end (); | ||
463 | return; | ||
464 | } | ||
465 | if (is_asymmetric_send_constant == GNUNET_YES) | ||
466 | { | ||
467 | if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA) | ||
468 | measure (current_quota_p1 * 2, MEASUREMENT_MAX_QUOTA); | ||
469 | else | ||
470 | measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA); | ||
471 | } | ||
472 | else if (is_asymmetric_recv_constant == GNUNET_YES) | ||
473 | { | ||
474 | if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA) | ||
475 | measure (MEASUREMENT_MAX_QUOTA, current_quota_p2 * 2); | ||
476 | else | ||
477 | measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA); | ||
478 | } | ||
479 | else | ||
480 | { | ||
481 | if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA) | ||
482 | measure ((current_quota_p1) * 2, (current_quota_p2) * 2); | ||
483 | else | ||
484 | measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA); | ||
485 | } | ||
486 | } | 454 | } |
487 | 455 | ||
488 | static void | 456 | static char * |
489 | measure (unsigned long long quota_p1, unsigned long long quota_p2) | 457 | generate_config (char * cfg_file_p1, unsigned long long quota_in, unsigned long long quota_out) |
490 | { | 458 | { |
491 | current_quota_p1 = quota_p1; | 459 | char * fname = NULL; |
492 | current_quota_p2 = quota_p2; | 460 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create(); |
493 | #if VERBOSE | 461 | GNUNET_CONFIGURATION_load (cfg, cfg_file_p1); |
494 | if ((is_asymmetric_send_constant == GNUNET_YES) || | ||
495 | (is_asymmetric_recv_constant == GNUNET_YES)) | ||
496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
497 | "Starting transport level measurement for %u seconds, receiving peer quota %llu kB/s, sending peer quota %llu kB/s\n", | ||
498 | MEASUREMENT_INTERVALL.rel_value / 1000, current_quota_p1 / 1024, | ||
499 | current_quota_p2 / 1024); | ||
500 | else | ||
501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
502 | "Starting transport level measurement for %u seconds, symmetric quota %llu kB/s\n", | ||
503 | MEASUREMENT_INTERVALL.rel_value / 1000, | ||
504 | current_quota_p2 / 1024); | ||
505 | 462 | ||
506 | #endif | 463 | GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_IN", quota_in); |
507 | GNUNET_TRANSPORT_set_quota (p1.th, &p2.id, | 464 | GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_OUT", quota_out); |
508 | GNUNET_BANDWIDTH_value_init (current_quota_p1), | ||
509 | GNUNET_BANDWIDTH_value_init (current_quota_p1)); | ||
510 | GNUNET_TRANSPORT_set_quota (p2.th, &p1.id, | ||
511 | GNUNET_BANDWIDTH_value_init (current_quota_p2), | ||
512 | GNUNET_BANDWIDTH_value_init (current_quota_p2)); | ||
513 | GNUNET_SCHEDULER_cancel (die_task); | ||
514 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
515 | if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) | ||
516 | GNUNET_SCHEDULER_cancel (measurement_counter_task); | ||
517 | measurement_counter_task = | ||
518 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
519 | &measurement_counter, NULL); | ||
520 | measurement_task = | ||
521 | GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL, &measurement_end, | ||
522 | NULL); | ||
523 | total_bytes_sent = 0; | ||
524 | last_msg_sent = 0; | ||
525 | last_msg_recv = 0; | ||
526 | measurement_running = GNUNET_YES; | ||
527 | start_time = GNUNET_TIME_absolute_get (); | ||
528 | 465 | ||
529 | if (transmit_handle != NULL) | 466 | GNUNET_asprintf (&fname, "q_in_%ull_q_out_%ull_%s", quota_in, quota_out, cfg_file_p1); |
530 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle); | ||
531 | transmit_handle = | ||
532 | GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, get_size (), 0, | ||
533 | SEND_TIMEOUT, ¬ify_ready, | ||
534 | NULL); | ||
535 | } | ||
536 | 467 | ||
468 | GNUNET_CONFIGURATION_write(cfg, fname); | ||
469 | GNUNET_CONFIGURATION_destroy(cfg); | ||
537 | 470 | ||
538 | static void | 471 | return fname; |
539 | exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message) | ||
540 | { | ||
541 | struct PeerContext *me = cls; | ||
542 | |||
543 | GNUNET_assert (message != NULL); | ||
544 | #if DEBUG_CONNECTIONS | ||
545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
546 | "Exchanging HELLO of size %d with peer (%s)!\n", | ||
547 | (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) | ||
548 | message), GNUNET_i2s (&me->id)); | ||
549 | #endif | ||
550 | GNUNET_assert (GNUNET_OK == | ||
551 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | ||
552 | message, &me->id)); | ||
553 | GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); | ||
554 | } | 472 | } |
555 | 473 | ||
556 | |||
557 | |||
558 | static void | 474 | static void |
559 | exchange_hello (void *cls, const struct GNUNET_MessageHeader *message) | 475 | run_measurement (unsigned long long p1_quota_in, unsigned long long p1_quota_out, |
476 | unsigned long long p2_quota_in, unsigned long long p2_quota_out) | ||
560 | { | 477 | { |
561 | struct PeerContext *me = cls; | 478 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
562 | 479 | ||
563 | GNUNET_assert (message != NULL); | 480 | /* setting ATS quota */ |
564 | GNUNET_assert (GNUNET_OK == | 481 | quota_out_p1 = p1_quota_out; |
565 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 482 | gen_cfg_p1 = generate_config(cfg_file_p1, p1_quota_in, p1_quota_out); |
566 | message, &me->id)); | ||
567 | #if DEBUG_CONNECTIONS | ||
568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
569 | "Exchanging HELLO of size %d from peer %s!\n", | 484 | "Generated config file `%s'\n", |
570 | (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) | 485 | gen_cfg_p1); |
571 | message), GNUNET_i2s (&me->id)); | ||
572 | #endif | ||
573 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | ||
574 | } | ||
575 | |||
576 | 486 | ||
577 | static void | 487 | quota_in_p2 = p2_quota_in; |
578 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | 488 | gen_cfg_p2 = generate_config(cfg_file_p2, p2_quota_in, p2_quota_out); |
579 | const struct GNUNET_ATS_Information *ats, | 489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
580 | uint32_t ats_count) | 490 | "Generated config file `%s'\n", |
581 | { | 491 | gen_cfg_p2); |
582 | connected++; | 492 | |
583 | if (cls == &p1) | 493 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, |
584 | { | 494 | ¬ify_receive, |
585 | #if DEBUG_CONNECTIONS | 495 | ¬ify_connect, ¬ify_disconnect, |
586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 `%4s' connected to us (%p)!\n", | 496 | &start_cb, |
587 | GNUNET_i2s (peer), cls); | 497 | NULL); |
588 | #endif | 498 | |
589 | } | 499 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, |
590 | else | 500 | ¬ify_receive, |
591 | { | 501 | ¬ify_connect, ¬ify_disconnect, |
592 | #if DEBUG_CONNECTIONS | 502 | &start_cb, |
593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 `%4s' connected to us (%p)!\n", | 503 | NULL); |
594 | GNUNET_i2s (peer), cls); | 504 | |
595 | #endif | 505 | if ((p1 == NULL) || (p2 == NULL)) |
596 | } | 506 | { |
597 | if (connected == 2) | 507 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); |
598 | { | 508 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
599 | if (GNUNET_SCHEDULER_NO_TASK != tct) | 509 | GNUNET_SCHEDULER_cancel (die_task); |
600 | { | 510 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
601 | GNUNET_SCHEDULER_cancel (tct); | 511 | return; |
602 | tct = GNUNET_SCHEDULER_NO_TASK; | ||
603 | } | ||
604 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); | ||
605 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); | ||
606 | if (is_asymmetric_send_constant == GNUNET_YES) | ||
607 | measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MAX_QUOTA); | ||
608 | else if (is_asymmetric_recv_constant == GNUNET_YES) | ||
609 | measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MIN_QUOTA); | ||
610 | else | ||
611 | measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA); | ||
612 | } | 512 | } |
613 | } | 513 | } |
614 | 514 | ||
615 | |||
616 | static void | 515 | static void |
617 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 516 | run (void *cls, char *const *args, const char *cfgfile, |
517 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
618 | { | 518 | { |
619 | if (cls == &p2) | 519 | run_measurement (10000, 10000, 10000, 10000); |
620 | { | ||
621 | if (NULL != transmit_handle) | ||
622 | { | ||
623 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle); | ||
624 | transmit_handle = NULL; | ||
625 | } | ||
626 | } | ||
627 | connected--; | ||
628 | #if DEBUG_CONNECTIONS | ||
629 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n", | ||
630 | GNUNET_i2s (peer), cls); | ||
631 | #endif | ||
632 | } | 520 | } |
633 | 521 | ||
634 | 522 | static int | |
635 | static void | 523 | check () |
636 | setup_peer (struct PeerContext *p, const char *cfgname) | ||
637 | { | 524 | { |
638 | p->cfg = GNUNET_CONFIGURATION_create (); | 525 | static char *argv[] = { "test_transport-quota-compliance", |
639 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 526 | "-c", |
640 | if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) | 527 | "test_transport_api_data.conf", |
641 | { | 528 | #if VERBOSE |
642 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", | 529 | "-L", "DEBUG", |
643 | &p->servicehome); | ||
644 | GNUNET_DISK_directory_remove (p->servicehome); | ||
645 | } | ||
646 | |||
647 | #if START_ARM | ||
648 | p->arm_proc = | ||
649 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | ||
650 | "gnunet-service-arm", | ||
651 | #if VERBOSE_ARM | ||
652 | "-L", "DEBUG", | ||
653 | #endif | ||
654 | "-c", cfgname, NULL); | ||
655 | #endif | 530 | #endif |
531 | NULL | ||
532 | }; | ||
533 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
534 | GNUNET_GETOPT_OPTION_END | ||
535 | }; | ||
656 | 536 | ||
657 | p->th = | 537 | ok = 1; |
658 | GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive_new, | 538 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, |
659 | ¬ify_connect, ¬ify_disconnect); | 539 | "nohelp", options, &run, &ok); |
660 | GNUNET_assert (p->th != NULL); | ||
661 | } | ||
662 | 540 | ||
541 | return ok; | ||
542 | } | ||
663 | 543 | ||
664 | static void | 544 | int |
665 | try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 545 | main (int argc, char *argv[]) |
666 | { | 546 | { |
667 | #if DEBUG_CONNECTIONS | 547 | int ret; |
668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n"); | 548 | int nat_res; |
669 | #endif | ||
670 | GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); | ||
671 | GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); | ||
672 | tct = | ||
673 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, | ||
674 | NULL); | ||
675 | } | ||
676 | 549 | ||
550 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
677 | 551 | ||
678 | static void | 552 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); |
679 | run (void *cls, char *const *args, const char *cfgfile, | 553 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, |
680 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 554 | &test_plugin); |
681 | { | 555 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); |
682 | GNUNET_assert (ok == 1); | ||
683 | OKPP; | ||
684 | 556 | ||
685 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 557 | GNUNET_log_setup (test_name, |
686 | measurement_running = GNUNET_NO; | 558 | #if VERBOSE |
687 | send_running = GNUNET_NO; | 559 | "DEBUG", |
688 | recv_running = GNUNET_NO; | 560 | #else |
561 | "WARNING", | ||
562 | #endif | ||
563 | NULL); | ||
689 | 564 | ||
690 | if (is_tcp) | 565 | if ((strcmp (test_plugin, "tcp_nat") == 0) || |
566 | (strcmp (test_plugin, "udp_nat") == 0)) | ||
691 | { | 567 | { |
692 | if (is_asymmetric_recv_constant == GNUNET_YES) | 568 | nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server"); |
693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 569 | if (GNUNET_NO == nat_res) |
694 | "Testing asymmetric quota compliance (receiver quota constant) for TCP transport plugin\n"); | 570 | { |
695 | else if (is_asymmetric_send_constant == GNUNET_YES) | 571 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", |
696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 572 | "gnunet-nat-server", "SUID not set"); |
697 | "Testing asymmetric quota compliance (sender quota constant) for TCP transport plugin\n"); | 573 | return 0; |
698 | else | 574 | } |
699 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 575 | if (GNUNET_SYSERR == nat_res) |
700 | "Testing symmetric quota compliance for TCP transport plugin\n"); | 576 | { |
701 | setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf"); | 577 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", |
702 | setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf"); | 578 | "gnunet-nat-server", "file not found"); |
703 | } | 579 | return 0; |
704 | else if (is_http) | 580 | } |
705 | { | ||
706 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
708 | "Testing asymmetric quota compliance (receiver quota constant) for HTTP transport plugin\n"); | ||
709 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
710 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
711 | "Testing asymmetric quota compliance (sender quota constant) for HTTP transport plugin\n"); | ||
712 | else | ||
713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
714 | "Testing symmetric quota compliance for HTTP transport plugin\n"); | ||
715 | setup_peer (&p1, "test_quota_compliance_http_peer1.conf"); | ||
716 | setup_peer (&p2, "test_quota_compliance_http_peer2.conf"); | ||
717 | } | ||
718 | else if (is_https) | ||
719 | { | ||
720 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
722 | "Testing asymmetric quota compliance (receiver quota constant) for HTTPS transport plugin\n"); | ||
723 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
724 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
725 | "Testing asymmetric quota compliance (sender quota constant) for HTTPS transport plugin\n"); | ||
726 | else | ||
727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
728 | "Testing symmetric quota compliance for HTTPS transport plugin\n"); | ||
729 | setup_peer (&p1, "test_quota_compliance_https_peer1.conf"); | ||
730 | setup_peer (&p2, "test_quota_compliance_https_peer2.conf"); | ||
731 | } | ||
732 | else if (is_udp) | ||
733 | { | ||
734 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
736 | "Testing asymmetric quota compliance (receiver quota constant) for UDP transport plugin\n"); | ||
737 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
739 | "Testing asymmetric quota compliance (sender quota constant) for UDP transport plugin\n"); | ||
740 | else | ||
741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
742 | "Testing symmetric quota compliance for UDP transport plugin\n"); | ||
743 | setup_peer (&p1, "test_quota_compliance_udp_peer1.conf"); | ||
744 | setup_peer (&p2, "test_quota_compliance_udp_peer2.conf"); | ||
745 | } | ||
746 | else if (is_unix) | ||
747 | { | ||
748 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
750 | "Testing asymmetric quota compliance (receiver quota constant) for UNIX transport plugin\n"); | ||
751 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
753 | "Testing asymmetric quota compliance (sender quota constant) for UNIX transport plugin\n"); | ||
754 | else | ||
755 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
756 | "Testing symmetric quota compliance for UNIX transport plugin\n"); | ||
757 | setup_peer (&p1, "test_quota_compliance_unix_peer1.conf"); | ||
758 | setup_peer (&p2, "test_quota_compliance_unix_peer2.conf"); | ||
759 | } | ||
760 | else if (is_tcp_nat) | ||
761 | { | ||
762 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
764 | "Testing asymmetric quota compliance (receiver quota constant) for TCP NAT transport plugin\n"); | ||
765 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
767 | "Testing asymmetric quota compliance (sender quota constant) for TCP NAT transport plugin\n"); | ||
768 | else | ||
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
770 | "Testing symmetric quota compliance for TCP NAT transport plugin\n"); | ||
771 | setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf"); | ||
772 | setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf"); | ||
773 | } | 581 | } |
774 | else | ||
775 | GNUNET_assert (0); | ||
776 | 582 | ||
777 | GNUNET_assert (p1.th != NULL); | 583 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); |
778 | GNUNET_assert (p2.th != NULL); | 584 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); |
779 | p1.ghh = GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); | ||
780 | p2.ghh = GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); | ||
781 | tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL); | ||
782 | } | ||
783 | 585 | ||
586 | ret = check (); | ||
784 | 587 | ||
785 | int | 588 | GNUNET_free (cfg_file_p1); |
786 | main (int argc, char *argv[]) | 589 | GNUNET_free (cfg_file_p2); |
787 | { | ||
788 | int ret = 0; | ||
789 | 590 | ||
790 | if (strstr (argv[0], "tcp_nat") != NULL) | 591 | if (GNUNET_YES == GNUNET_DISK_file_test (gen_cfg_p1)) |
791 | { | ||
792 | is_tcp_nat = GNUNET_YES; | ||
793 | } | ||
794 | else if (strstr (argv[0], "tcp") != NULL) | ||
795 | { | ||
796 | is_tcp = GNUNET_YES; | ||
797 | } | ||
798 | else if (strstr (argv[0], "https") != NULL) | ||
799 | { | ||
800 | is_https = GNUNET_YES; | ||
801 | } | ||
802 | else if (strstr (argv[0], "http") != NULL) | ||
803 | { | 592 | { |
804 | is_http = GNUNET_YES; | 593 | GNUNET_DISK_directory_remove (gen_cfg_p1); |
805 | } | 594 | GNUNET_free (gen_cfg_p1); |
806 | else if (strstr (argv[0], "udp") != NULL) | ||
807 | { | ||
808 | is_udp = GNUNET_YES; | ||
809 | } | ||
810 | else if (strstr (argv[0], "unix") != NULL) | ||
811 | { | ||
812 | is_unix = GNUNET_YES; | ||
813 | } | 595 | } |
814 | 596 | ||
815 | if (strstr (argv[0], "asymmetric_recv") != NULL) | 597 | if (GNUNET_YES == GNUNET_DISK_file_test (gen_cfg_p2)) |
816 | { | 598 | { |
817 | is_asymmetric_recv_constant = GNUNET_YES; | 599 | //GNUNET_DISK_directory_remove (gen_cfg_p2); |
600 | GNUNET_free (gen_cfg_p2); | ||
818 | } | 601 | } |
819 | else | ||
820 | is_asymmetric_recv_constant = GNUNET_NO; | ||
821 | if (strstr (argv[0], "asymmetric_send") != NULL) | ||
822 | { | ||
823 | is_asymmetric_send_constant = GNUNET_YES; | ||
824 | } | ||
825 | else | ||
826 | is_asymmetric_send_constant = GNUNET_NO; | ||
827 | 602 | ||
828 | char *logger; | 603 | GNUNET_free (test_source); |
604 | GNUNET_free (test_plugin); | ||
605 | GNUNET_free (test_name); | ||
829 | 606 | ||
830 | if (is_tcp == GNUNET_YES) | 607 | GNUNET_TRANSPORT_TESTING_done (tth); |
831 | { | ||
832 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
833 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp", | ||
834 | "asymmetric_recv_constant"); | ||
835 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
836 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp", | ||
837 | "asymmetric_send_constant"); | ||
838 | else | ||
839 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp", | ||
840 | "symmetric"); | ||
841 | } | ||
842 | else if (is_udp == GNUNET_YES) | ||
843 | { | ||
844 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
845 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp", | ||
846 | "asymmetric_recv_constant"); | ||
847 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
848 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp", | ||
849 | "asymmetric_send_constant"); | ||
850 | else | ||
851 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp", | ||
852 | "symmetric"); | ||
853 | } | ||
854 | else if (is_unix == GNUNET_YES) | ||
855 | { | ||
856 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
857 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix", | ||
858 | "asymmetric_recv_constant"); | ||
859 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
860 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix", | ||
861 | "asymmetric_send_constant"); | ||
862 | else | ||
863 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix", | ||
864 | "symmetric"); | ||
865 | } | ||
866 | else if (is_http == GNUNET_YES) | ||
867 | { | ||
868 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
869 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http", | ||
870 | "asymmetric_recv_constant"); | ||
871 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
872 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http", | ||
873 | "asymmetric_send_constant"); | ||
874 | else | ||
875 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http", | ||
876 | "symmetric"); | ||
877 | } | ||
878 | else if (is_https == GNUNET_YES) | ||
879 | { | ||
880 | if (is_asymmetric_recv_constant == GNUNET_YES) | ||
881 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https", | ||
882 | "asymmetric_recv_constant"); | ||
883 | else if (is_asymmetric_send_constant == GNUNET_YES) | ||
884 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https", | ||
885 | "asymmetric_send_constant"); | ||
886 | else | ||
887 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https", | ||
888 | "symmetric"); | ||
889 | } | ||
890 | else | ||
891 | { | ||
892 | GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "noplugin", | ||
893 | "none"); | ||
894 | } | ||
895 | 608 | ||
896 | fprintf (stderr, "Running `%s'\n", logger); | ||
897 | GNUNET_log_setup ("test-quota-compliance", | ||
898 | #if VERBOSE | ||
899 | "DEBUG", | ||
900 | #else | ||
901 | "WARNING", | ||
902 | #endif | ||
903 | NULL); | ||
904 | char *const argv1[] = { "test-quota-compliance", | ||
905 | "-c", | ||
906 | "test_quota_compliance_data.conf", | ||
907 | #if VERBOSE | ||
908 | "-L", "DEBUG", | ||
909 | #endif | ||
910 | NULL | ||
911 | }; | ||
912 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
913 | GNUNET_GETOPT_OPTION_END | ||
914 | }; | ||
915 | ok = 1; | ||
916 | GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1, argv1, logger, | ||
917 | "nohelp", options, &run, &ok); | ||
918 | ret = ok; | ||
919 | stop_arm (&p1); | ||
920 | stop_arm (&p2); | ||
921 | |||
922 | if (p1.servicehome != NULL) | ||
923 | { | ||
924 | GNUNET_DISK_directory_remove (p1.servicehome); | ||
925 | GNUNET_free (p1.servicehome); | ||
926 | } | ||
927 | if (p2.servicehome != NULL) | ||
928 | { | ||
929 | GNUNET_DISK_directory_remove (p2.servicehome); | ||
930 | GNUNET_free (p2.servicehome); | ||
931 | } | ||
932 | GNUNET_free (logger); | ||
933 | return ret; | 609 | return ret; |
934 | } | 610 | } |
935 | 611 | ||
612 | |||
936 | /* end of test_quota_compliance.c */ | 613 | /* end of test_quota_compliance.c */ |