Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include "controller.hh"
  4. #include "timestamp.hh"
  5.  
  6. using namespace std;
  7.  
  8. /* Default constructor */
  9. Controller::Controller( const bool debug )
  10. : debug_( debug ), the_window_size(20), package_counter(0), total_rtt(0)
  11. {}
  12.  
  13. /* Get current window size, in datagrams */
  14. unsigned int Controller::window_size()
  15. {
  16. /* Default: fixed window size of 100 outstanding datagrams */
  17. //unsigned int the_window_size = 50;
  18.  
  19. if ( debug_ ) {
  20. cerr << "At time " << timestamp_ms()
  21. << " window size is " << the_window_size << endl;
  22. }
  23.  
  24. return the_window_size;
  25. }
  26.  
  27. /* A datagram was sent */
  28. void Controller::datagram_was_sent( const uint64_t sequence_number,
  29. /* of the sent datagram */
  30. const uint64_t send_timestamp,
  31. /* in milliseconds */
  32. const bool after_timeout
  33. /* datagram was sent because of a timeout */ )
  34. {
  35. /* Default: take no action */
  36. if(after_timeout) {
  37. the_window_size = 20;
  38. }
  39.  
  40. if ( debug_ ) {
  41. cerr << "At time " << send_timestamp
  42. << " sent datagram " << sequence_number << " (timeout = " << after_timeout << ")\n";
  43. }
  44. }
  45.  
  46. /* An ack was received */
  47. void Controller::ack_received( const uint64_t sequence_number_acked,
  48. /* what sequence number was acknowledged */
  49. const uint64_t send_timestamp_acked,
  50. /* when the acknowledged datagram was sent (sender's clock) */
  51. const uint64_t recv_timestamp_acked,
  52. /* when the acknowledged datagram was received (receiver's clock)*/
  53. const uint64_t timestamp_ack_received )
  54. /* when the ack was received (by sender) */
  55. {
  56. /* Default: take no action */
  57.  
  58. const uint64_t rtt_value = timestamp_ack_received - send_timestamp_acked;
  59.  
  60. //cerr << "Current RTT" << rtt_value << endl;
  61.  
  62.  
  63. /** ----Implementação do aimd ----
  64. / além de chegar um limite para fazer a redução da janela, é necessário considerar
  65. / todos os pacotes que estavam conjestionados após a identificação do primeiro
  66. / sem essa validação, o algoritmo irá considerar o RTT de todos esses pacotes
  67. / reduzindo o tamanho da janela mais vezes do que o necessário
  68. **/
  69. // const uint64_t threshold = 90;
  70. // if(rtt_value >= threshold) {
  71. // cerr << "LIMIT BREAK" << endl;
  72. // the_window_size = (the_window_size * 1/2);
  73. // } else {
  74. // the_window_size += 1;
  75. // }
  76.  
  77. const uint64_t threshold = 65;
  78. if(rtt_value >= threshold) {
  79. // cerr << "LIMIT BREAK" << endl;
  80. // if (the_window_size <= 15)
  81. // the_window_size = 15
  82. // else
  83. the_window_size = 1 + floor(the_window_size * 9/10);
  84. } else {
  85. the_window_size += 1;
  86. }
  87.  
  88. //if(rtt_value >= threshold) {
  89. //cerr << "LIMIT BREAK" << endl;
  90. // }
  91.  
  92. // if (package_counter >= the_window_size) {
  93. // const uint64_t threshold = 90;
  94. // if (rtt_value >= threshold) {
  95. // the_window_size = the_window_size * 2 / 3;
  96. // } else {
  97. // the_window_size += 1;
  98. // }
  99. // package_counter = 0;
  100. // } else {
  101. // package_counter += 1;
  102. // }
  103.  
  104. if ( debug_ ) {
  105. cerr << "At time " << timestamp_ack_received
  106. << " received ack for datagram " << sequence_number_acked
  107. << " (send @ time " << send_timestamp_acked
  108. << ", received @ time " << recv_timestamp_acked << " by receiver's clock)"
  109. << endl;
  110. }
  111. }
  112.  
  113. /* How long to wait (in milliseconds) if there are no acks
  114. before sending one more datagram */
  115. unsigned int Controller::timeout_ms()
  116. {
  117. return 1000; /* timeout of one second */
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement