OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The tests in this file attempt to verify the following through simulation: | 5 // The tests in this file attempt to verify the following through simulation: |
6 // a) That a server experiencing overload will actually benefit from the | 6 // a) That a server experiencing overload will actually benefit from the |
7 // anti-DDoS throttling logic, i.e. that its traffic spike will subside | 7 // anti-DDoS throttling logic, i.e. that its traffic spike will subside |
8 // and be distributed over a longer period of time; | 8 // and be distributed over a longer period of time; |
9 // b) That "well-behaved" clients of a server under DDoS attack actually | 9 // b) That "well-behaved" clients of a server under DDoS attack actually |
10 // benefit from the anti-DDoS throttling logic; and | 10 // benefit from the anti-DDoS throttling logic; and |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 { TimeDelta::FromMinutes(80), TimeDelta::FromMinutes(3) }, | 711 { TimeDelta::FromMinutes(80), TimeDelta::FromMinutes(3) }, |
712 { TimeDelta::FromMinutes(80), TimeDelta::FromSeconds(15) }, | 712 { TimeDelta::FromMinutes(80), TimeDelta::FromSeconds(15) }, |
713 | 713 |
714 // Most brutal? | 714 // Most brutal? |
715 { TimeDelta::FromMinutes(45), TimeDelta::FromMilliseconds(500) }, | 715 { TimeDelta::FromMinutes(45), TimeDelta::FromMilliseconds(500) }, |
716 }; | 716 }; |
717 | 717 |
718 // If things don't converge by the time we've done 100K trials, then | 718 // If things don't converge by the time we've done 100K trials, then |
719 // clearly one or more of the expected intervals are wrong. | 719 // clearly one or more of the expected intervals are wrong. |
720 while (global_stats.num_runs < 100000) { | 720 while (global_stats.num_runs < 100000) { |
721 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(trials); ++i) { | 721 for (size_t i = 0; i < arraysize(trials); ++i) { |
722 ++global_stats.num_runs; | 722 ++global_stats.num_runs; |
723 ++trials[i].stats.num_runs; | 723 ++trials[i].stats.num_runs; |
724 double ratio_unprotected = SimulateDowntime( | 724 double ratio_unprotected = SimulateDowntime( |
725 trials[i].duration, trials[i].average_client_interval, false); | 725 trials[i].duration, trials[i].average_client_interval, false); |
726 double ratio_protected = SimulateDowntime( | 726 double ratio_protected = SimulateDowntime( |
727 trials[i].duration, trials[i].average_client_interval, true); | 727 trials[i].duration, trials[i].average_client_interval, true); |
728 global_stats.total_ratio_unprotected += ratio_unprotected; | 728 global_stats.total_ratio_unprotected += ratio_unprotected; |
729 global_stats.total_ratio_protected += ratio_protected; | 729 global_stats.total_ratio_protected += ratio_protected; |
730 trials[i].stats.total_ratio_unprotected += ratio_unprotected; | 730 trials[i].stats.total_ratio_unprotected += ratio_unprotected; |
731 trials[i].stats.total_ratio_protected += ratio_protected; | 731 trials[i].stats.total_ratio_protected += ratio_protected; |
732 } | 732 } |
733 | 733 |
734 double increase_ratio; | 734 double increase_ratio; |
735 if (global_stats.DidConverge(&increase_ratio)) | 735 if (global_stats.DidConverge(&increase_ratio)) |
736 break; | 736 break; |
737 | 737 |
738 if (global_stats.num_runs > 200) { | 738 if (global_stats.num_runs > 200) { |
739 VerboseOut("Test has not yet converged on expected interval.\n"); | 739 VerboseOut("Test has not yet converged on expected interval.\n"); |
740 global_stats.ReportTrialResult(increase_ratio); | 740 global_stats.ReportTrialResult(increase_ratio); |
741 } | 741 } |
742 } | 742 } |
743 | 743 |
744 double average_increase_ratio; | 744 double average_increase_ratio; |
745 EXPECT_TRUE(global_stats.DidConverge(&average_increase_ratio)); | 745 EXPECT_TRUE(global_stats.DidConverge(&average_increase_ratio)); |
746 | 746 |
747 // Print individual trial results for optional manual evaluation. | 747 // Print individual trial results for optional manual evaluation. |
748 double max_increase_ratio = 0.0; | 748 double max_increase_ratio = 0.0; |
749 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(trials); ++i) { | 749 for (size_t i = 0; i < arraysize(trials); ++i) { |
750 double increase_ratio; | 750 double increase_ratio; |
751 trials[i].stats.DidConverge(&increase_ratio); | 751 trials[i].stats.DidConverge(&increase_ratio); |
752 max_increase_ratio = std::max(max_increase_ratio, increase_ratio); | 752 max_increase_ratio = std::max(max_increase_ratio, increase_ratio); |
753 trials[i].PrintTrialDescription(); | 753 trials[i].PrintTrialDescription(); |
754 trials[i].stats.ReportTrialResult(increase_ratio); | 754 trials[i].stats.ReportTrialResult(increase_ratio); |
755 } | 755 } |
756 | 756 |
757 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); | 757 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); |
758 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); | 758 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); |
759 } | 759 } |
760 | 760 |
761 } // namespace | 761 } // namespace |
762 } // namespace net | 762 } // namespace net |
OLD | NEW |