aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-11 17:00:40 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-11 17:00:40 +0000
commit9e8d96ae528a7bc3e38d212129ee63727a21d612 (patch)
treea513add7584b81069f0aff2d7886c5fd91731c8c
parent06081068ed6315a01d9ecd201d6c3bccb9ebfecd (diff)
downloadgnunet-9e8d96ae528a7bc3e38d212129ee63727a21d612.tar.gz
gnunet-9e8d96ae528a7bc3e38d212129ee63727a21d612.zip
add command to test reservations
-rw-r--r--src/ats/test_ats_lib.c70
-rw-r--r--src/ats/test_ats_lib.h42
2 files changed, 109 insertions, 3 deletions
diff --git a/src/ats/test_ats_lib.c b/src/ats/test_ats_lib.c
index 74cff1e61..b55881b6e 100644
--- a/src/ats/test_ats_lib.c
+++ b/src/ats/test_ats_lib.c
@@ -404,7 +404,8 @@ make_address (uint32_t pid,
404/** 404/**
405 * Our dummy sessions. 405 * Our dummy sessions.
406 */ 406 */
407struct Session { 407struct Session
408{
408 /** 409 /**
409 * Field to avoid `0 == sizeof(struct Session)`. 410 * Field to avoid `0 == sizeof(struct Session)`.
410 */ 411 */
@@ -522,6 +523,59 @@ info_cb (void *cls,
522 523
523 524
524/** 525/**
526 * Function called with reservation result.
527 *
528 * @param cls closure with the reservation command (`struct Command`)
529 * @param peer identifies the peer
530 * @param amount set to the amount that was actually reserved or unreserved;
531 * either the full requested amount or zero (no partial reservations)
532 * @param res_delay if the reservation could not be satisfied (amount was 0), how
533 * long should the client wait until re-trying?
534 */
535static void
536reservation_cb (void *cls,
537 const struct GNUNET_PeerIdentity *peer,
538 int32_t amount,
539 struct GNUNET_TIME_Relative res_delay)
540{
541 struct Command *cmd = cls;
542 struct GNUNET_PeerIdentity pid;
543
544 make_peer (cmd->details.reserve_bandwidth.pid,
545 &pid);
546 GNUNET_assert (0 == memcmp (peer,
547 &pid,
548 sizeof (struct GNUNET_PeerIdentity)));
549 switch (cmd->details.reserve_bandwidth.expected_result)
550 {
551 case GNUNET_OK:
552 if (amount != cmd->details.reserve_bandwidth.amount)
553 {
554 GNUNET_break (0);
555 GNUNET_SCHEDULER_shutdown ();
556 return;
557 }
558 break;
559 case GNUNET_NO:
560 GNUNET_break ( (0 != amount) ||
561 (0 != res_delay.rel_value_us) );
562 break;
563 case GNUNET_SYSERR:
564 if ( (amount != cmd->details.reserve_bandwidth.amount) ||
565 (0 == res_delay.rel_value_us) )
566 {
567 GNUNET_break (0);
568 GNUNET_SCHEDULER_shutdown ();
569 return;
570 }
571 break;
572 }
573 off++;
574 run_interpreter ();
575}
576
577
578/**
525 * Main interpreter loop. Runs the steps of the test. 579 * Main interpreter loop. Runs the steps of the test.
526 * 580 *
527 * @param cls NULL 581 * @param cls NULL
@@ -779,6 +833,20 @@ interpreter (void *cls,
779 cmd); 833 cmd);
780 return; 834 return;
781 } 835 }
836 case CMD_RESERVE_BANDWIDTH:
837 {
838 struct GNUNET_PeerIdentity pid;
839
840 make_peer (cmd->details.reserve_bandwidth.pid,
841 &pid);
842 cmd->details.reserve_bandwidth.rc
843 = GNUNET_ATS_reserve_bandwidth (perf_ats,
844 &pid,
845 cmd->details.reserve_bandwidth.amount,
846 &reservation_cb,
847 cmd);
848 return;
849 }
782 } /* end switch */ 850 } /* end switch */
783 } /* end while(1) */ 851 } /* end while(1) */
784} 852}
diff --git a/src/ats/test_ats_lib.h b/src/ats/test_ats_lib.h
index 590aac750..099fa9b45 100644
--- a/src/ats/test_ats_lib.h
+++ b/src/ats/test_ats_lib.h
@@ -111,9 +111,13 @@ enum CommandCode
111 * Obtain list of all addresses, testing 111 * Obtain list of all addresses, testing
112 * #GNUNET_ATS_performance_list_addresses(). 112 * #GNUNET_ATS_performance_list_addresses().
113 */ 113 */
114 CMD_LIST_ADDRESSES 114 CMD_LIST_ADDRESSES,
115 115
116 /* TODO: reserve bandwidth */ 116 /**
117 * Reserve bandwidth, testing
118 * #GNUNET_ATS_reserve_bandwidth().
119 */
120 CMD_RESERVE_BANDWIDTH
117 121
118}; 122};
119 123
@@ -399,6 +403,38 @@ struct CommandListAddresses
399 403
400 404
401/** 405/**
406 * Details for the #CMD_RESERVE_BANDWIDTH command.
407 */
408struct CommandReserveBandwidth
409{
410 /**
411 * For which peer do we reserve bandwidth?
412 */
413 unsigned int pid;
414
415 /**
416 * How much should we try to reserve?
417 */
418 int32_t amount;
419
420 /**
421 * Should we expect this to work or fail?
422 * #GNUNET_YES: must work
423 * #GNUNET_NO: may work or fail
424 * #GNUNET_SYSERR: must fail
425 */
426 int expected_result;
427
428 /**
429 * Location where we store the return value from
430 * #GNUNET_ATS_reserve_bandwidth().
431 */
432 struct GNUNET_ATS_ReservationContext *rc;
433
434};
435
436
437/**
402 * A command for the test case interpreter. 438 * A command for the test case interpreter.
403 */ 439 */
404struct Command 440struct Command
@@ -444,6 +480,8 @@ struct Command
444 480
445 struct CommandListAddresses list_addresses; 481 struct CommandListAddresses list_addresses;
446 482
483 struct CommandReserveBandwidth reserve_bandwidth;
484
447 } details; 485 } details;
448 486
449}; 487};