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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 class Server : public DiscreteTimeSimulation::Actor { | 117 class Server : public DiscreteTimeSimulation::Actor { |
118 public: | 118 public: |
119 Server(int max_queries_per_tick, | 119 Server(int max_queries_per_tick, |
120 double request_drop_ratio) | 120 double request_drop_ratio) |
121 : max_queries_per_tick_(max_queries_per_tick), | 121 : max_queries_per_tick_(max_queries_per_tick), |
122 request_drop_ratio_(request_drop_ratio), | 122 request_drop_ratio_(request_drop_ratio), |
123 num_overloaded_ticks_remaining_(0), | 123 num_overloaded_ticks_remaining_(0), |
124 num_current_tick_queries_(0), | 124 num_current_tick_queries_(0), |
125 num_overloaded_ticks_(0), | 125 num_overloaded_ticks_(0), |
126 max_experienced_queries_per_tick_(0), | 126 max_experienced_queries_per_tick_(0), |
127 mock_request_(GURL(), NULL) { | 127 mock_request_(GURL(), NULL, &context_) { |
128 } | 128 } |
129 | 129 |
130 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { | 130 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { |
131 start_downtime_ = start_time; | 131 start_downtime_ = start_time; |
132 end_downtime_ = start_time + duration; | 132 end_downtime_ = start_time + duration; |
133 } | 133 } |
134 | 134 |
135 virtual void AdvanceTime(const TimeTicks& absolute_time) OVERRIDE { | 135 virtual void AdvanceTime(const TimeTicks& absolute_time) OVERRIDE { |
136 now_ = absolute_time; | 136 now_ = absolute_time; |
137 } | 137 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 TimeTicks now_; | 280 TimeTicks now_; |
281 TimeTicks start_downtime_; // Can be 0 to say "no downtime". | 281 TimeTicks start_downtime_; // Can be 0 to say "no downtime". |
282 TimeTicks end_downtime_; | 282 TimeTicks end_downtime_; |
283 const int max_queries_per_tick_; | 283 const int max_queries_per_tick_; |
284 const double request_drop_ratio_; // Ratio of requests to 503 when failing. | 284 const double request_drop_ratio_; // Ratio of requests to 503 when failing. |
285 int num_overloaded_ticks_remaining_; | 285 int num_overloaded_ticks_remaining_; |
286 int num_current_tick_queries_; | 286 int num_current_tick_queries_; |
287 int num_overloaded_ticks_; | 287 int num_overloaded_ticks_; |
288 int max_experienced_queries_per_tick_; | 288 int max_experienced_queries_per_tick_; |
289 std::vector<int> requests_per_tick_; | 289 std::vector<int> requests_per_tick_; |
| 290 |
| 291 TestURLRequestContext context_; |
290 TestURLRequest mock_request_; | 292 TestURLRequest mock_request_; |
291 | 293 |
292 DISALLOW_COPY_AND_ASSIGN(Server); | 294 DISALLOW_COPY_AND_ASSIGN(Server); |
293 }; | 295 }; |
294 | 296 |
295 // Mock throttler entry used by Requester class. | 297 // Mock throttler entry used by Requester class. |
296 class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry { | 298 class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry { |
297 public: | 299 public: |
298 explicit MockURLRequestThrottlerEntry( | 300 explicit MockURLRequestThrottlerEntry( |
299 URLRequestThrottlerManager* manager) | 301 URLRequestThrottlerManager* manager) |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 trials[i].PrintTrialDescription(); | 748 trials[i].PrintTrialDescription(); |
747 trials[i].stats.ReportTrialResult(increase_ratio); | 749 trials[i].stats.ReportTrialResult(increase_ratio); |
748 } | 750 } |
749 | 751 |
750 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); | 752 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); |
751 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); | 753 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); |
752 } | 754 } |
753 | 755 |
754 } // namespace | 756 } // namespace |
755 } // namespace net | 757 } // namespace net |
OLD | NEW |