| 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 |
| 11 // c) That the approximate increase in "perceived downtime" introduced by | 11 // c) That the approximate increase in "perceived downtime" introduced by |
| 12 // anti-DDoS throttling for various different actual downtimes is what | 12 // anti-DDoS throttling for various different actual downtimes is what |
| 13 // we expect it to be. | 13 // we expect it to be. |
| 14 | 14 |
| 15 #include <cmath> | 15 #include <cmath> |
| 16 #include <limits> | 16 #include <limits> |
| 17 #include <memory> | 17 #include <memory> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include "base/environment.h" | 20 #include "base/environment.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
| 23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "net/base/request_priority.h" | 24 #include "net/base/request_priority.h" |
| 25 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 25 #include "net/url_request/url_request.h" | 26 #include "net/url_request/url_request.h" |
| 26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
| 27 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
| 28 #include "net/url_request/url_request_throttler_manager.h" | 29 #include "net/url_request/url_request_throttler_manager.h" |
| 29 #include "net/url_request/url_request_throttler_test_support.h" | 30 #include "net/url_request/url_request_throttler_test_support.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| 32 using base::TimeDelta; | 33 using base::TimeDelta; |
| 33 using base::TimeTicks; | 34 using base::TimeTicks; |
| 34 | 35 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // after all |Requester| objects. | 121 // after all |Requester| objects. |
| 121 class Server : public DiscreteTimeSimulation::Actor { | 122 class Server : public DiscreteTimeSimulation::Actor { |
| 122 public: | 123 public: |
| 123 Server(int max_queries_per_tick, double request_drop_ratio) | 124 Server(int max_queries_per_tick, double request_drop_ratio) |
| 124 : max_queries_per_tick_(max_queries_per_tick), | 125 : max_queries_per_tick_(max_queries_per_tick), |
| 125 request_drop_ratio_(request_drop_ratio), | 126 request_drop_ratio_(request_drop_ratio), |
| 126 num_overloaded_ticks_remaining_(0), | 127 num_overloaded_ticks_remaining_(0), |
| 127 num_current_tick_queries_(0), | 128 num_current_tick_queries_(0), |
| 128 num_overloaded_ticks_(0), | 129 num_overloaded_ticks_(0), |
| 129 max_experienced_queries_per_tick_(0), | 130 max_experienced_queries_per_tick_(0), |
| 130 mock_request_(context_.CreateRequest(GURL(), DEFAULT_PRIORITY, NULL)) {} | 131 mock_request_(context_.CreateRequest(GURL(), |
| 132 DEFAULT_PRIORITY, |
| 133 NULL, |
| 134 TRAFFIC_ANNOTATION_FOR_TESTS)) {} |
| 131 | 135 |
| 132 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { | 136 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { |
| 133 start_downtime_ = start_time; | 137 start_downtime_ = start_time; |
| 134 end_downtime_ = start_time + duration; | 138 end_downtime_ = start_time + duration; |
| 135 } | 139 } |
| 136 | 140 |
| 137 void AdvanceTime(const TimeTicks& absolute_time) override { | 141 void AdvanceTime(const TimeTicks& absolute_time) override { |
| 138 now_ = absolute_time; | 142 now_ = absolute_time; |
| 139 } | 143 } |
| 140 | 144 |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 trials[i].PrintTrialDescription(); | 742 trials[i].PrintTrialDescription(); |
| 739 trials[i].stats.ReportTrialResult(increase_ratio); | 743 trials[i].stats.ReportTrialResult(increase_ratio); |
| 740 } | 744 } |
| 741 | 745 |
| 742 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); | 746 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); |
| 743 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); | 747 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); |
| 744 } | 748 } |
| 745 | 749 |
| 746 } // namespace | 750 } // namespace |
| 747 } // namespace net | 751 } // namespace net |
| OLD | NEW |