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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 num_overloaded_ticks_(0), | 128 num_overloaded_ticks_(0), |
129 max_experienced_queries_per_tick_(0), | 129 max_experienced_queries_per_tick_(0), |
130 mock_request_(context_.CreateRequest( | 130 mock_request_(context_.CreateRequest( |
131 GURL(), DEFAULT_PRIORITY, NULL, NULL)) {} | 131 GURL(), DEFAULT_PRIORITY, NULL, NULL)) {} |
132 | 132 |
133 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { | 133 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { |
134 start_downtime_ = start_time; | 134 start_downtime_ = start_time; |
135 end_downtime_ = start_time + duration; | 135 end_downtime_ = start_time + duration; |
136 } | 136 } |
137 | 137 |
138 virtual void AdvanceTime(const TimeTicks& absolute_time) override { | 138 void AdvanceTime(const TimeTicks& absolute_time) override { |
139 now_ = absolute_time; | 139 now_ = absolute_time; |
140 } | 140 } |
141 | 141 |
142 virtual void PerformAction() override { | 142 void PerformAction() override { |
143 // We are inserted at the end of the actor's list, so all Requester | 143 // We are inserted at the end of the actor's list, so all Requester |
144 // instances have already done their bit. | 144 // instances have already done their bit. |
145 if (num_current_tick_queries_ > max_experienced_queries_per_tick_) | 145 if (num_current_tick_queries_ > max_experienced_queries_per_tick_) |
146 max_experienced_queries_per_tick_ = num_current_tick_queries_; | 146 max_experienced_queries_per_tick_ = num_current_tick_queries_; |
147 | 147 |
148 if (num_current_tick_queries_ > max_queries_per_tick_) { | 148 if (num_current_tick_queries_ > max_queries_per_tick_) { |
149 // We pretend the server fails for the next several ticks after it | 149 // We pretend the server fails for the next several ticks after it |
150 // gets overloaded. | 150 // gets overloaded. |
151 num_overloaded_ticks_remaining_ = 5; | 151 num_overloaded_ticks_remaining_ = 5; |
152 ++num_overloaded_ticks_; | 152 ++num_overloaded_ticks_; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 DISALLOW_COPY_AND_ASSIGN(Server); | 299 DISALLOW_COPY_AND_ASSIGN(Server); |
300 }; | 300 }; |
301 | 301 |
302 // Mock throttler entry used by Requester class. | 302 // Mock throttler entry used by Requester class. |
303 class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry { | 303 class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry { |
304 public: | 304 public: |
305 explicit MockURLRequestThrottlerEntry(URLRequestThrottlerManager* manager) | 305 explicit MockURLRequestThrottlerEntry(URLRequestThrottlerManager* manager) |
306 : URLRequestThrottlerEntry(manager, std::string()), | 306 : URLRequestThrottlerEntry(manager, std::string()), |
307 mock_backoff_entry_(&backoff_policy_) {} | 307 mock_backoff_entry_(&backoff_policy_) {} |
308 | 308 |
309 virtual const BackoffEntry* GetBackoffEntry() const override { | 309 const BackoffEntry* GetBackoffEntry() const override { |
310 return &mock_backoff_entry_; | 310 return &mock_backoff_entry_; |
311 } | 311 } |
312 | 312 |
313 virtual BackoffEntry* GetBackoffEntry() override { | 313 BackoffEntry* GetBackoffEntry() override { return &mock_backoff_entry_; } |
314 return &mock_backoff_entry_; | |
315 } | |
316 | 314 |
317 virtual TimeTicks ImplGetTimeNow() const override { | 315 TimeTicks ImplGetTimeNow() const override { return fake_now_; } |
318 return fake_now_; | |
319 } | |
320 | 316 |
321 void SetFakeNow(const TimeTicks& fake_time) { | 317 void SetFakeNow(const TimeTicks& fake_time) { |
322 fake_now_ = fake_time; | 318 fake_now_ = fake_time; |
323 mock_backoff_entry_.set_fake_now(fake_time); | 319 mock_backoff_entry_.set_fake_now(fake_time); |
324 } | 320 } |
325 | 321 |
326 TimeTicks fake_now() const { | 322 TimeTicks fake_now() const { |
327 return fake_now_; | 323 return fake_now_; |
328 } | 324 } |
329 | 325 |
330 protected: | 326 protected: |
331 virtual ~MockURLRequestThrottlerEntry() {} | 327 ~MockURLRequestThrottlerEntry() override {} |
332 | 328 |
333 private: | 329 private: |
334 TimeTicks fake_now_; | 330 TimeTicks fake_now_; |
335 MockBackoffEntry mock_backoff_entry_; | 331 MockBackoffEntry mock_backoff_entry_; |
336 }; | 332 }; |
337 | 333 |
338 // Registry of results for a class of |Requester| objects (e.g. attackers vs. | 334 // Registry of results for a class of |Requester| objects (e.g. attackers vs. |
339 // regular clients). | 335 // regular clients). |
340 class RequesterResults { | 336 class RequesterResults { |
341 public: | 337 public: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 Server* server, | 403 Server* server, |
408 RequesterResults* results) | 404 RequesterResults* results) |
409 : throttler_entry_(throttler_entry), | 405 : throttler_entry_(throttler_entry), |
410 time_between_requests_(time_between_requests), | 406 time_between_requests_(time_between_requests), |
411 last_attempt_was_failure_(false), | 407 last_attempt_was_failure_(false), |
412 server_(server), | 408 server_(server), |
413 results_(results) { | 409 results_(results) { |
414 DCHECK(server_); | 410 DCHECK(server_); |
415 } | 411 } |
416 | 412 |
417 virtual void AdvanceTime(const TimeTicks& absolute_time) override { | 413 void AdvanceTime(const TimeTicks& absolute_time) override { |
418 if (time_of_last_success_.is_null()) | 414 if (time_of_last_success_.is_null()) |
419 time_of_last_success_ = absolute_time; | 415 time_of_last_success_ = absolute_time; |
420 | 416 |
421 throttler_entry_->SetFakeNow(absolute_time); | 417 throttler_entry_->SetFakeNow(absolute_time); |
422 } | 418 } |
423 | 419 |
424 virtual void PerformAction() override { | 420 void PerformAction() override { |
425 TimeDelta effective_delay = time_between_requests_; | 421 TimeDelta effective_delay = time_between_requests_; |
426 TimeDelta current_jitter = TimeDelta::FromMilliseconds( | 422 TimeDelta current_jitter = TimeDelta::FromMilliseconds( |
427 request_jitter_.InMilliseconds() * base::RandDouble()); | 423 request_jitter_.InMilliseconds() * base::RandDouble()); |
428 if (base::RandInt(0, 1)) { | 424 if (base::RandInt(0, 1)) { |
429 effective_delay -= current_jitter; | 425 effective_delay -= current_jitter; |
430 } else { | 426 } else { |
431 effective_delay += current_jitter; | 427 effective_delay += current_jitter; |
432 } | 428 } |
433 | 429 |
434 if (throttler_entry_->fake_now() - time_of_last_attempt_ > | 430 if (throttler_entry_->fake_now() - time_of_last_attempt_ > |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 trials[i].PrintTrialDescription(); | 749 trials[i].PrintTrialDescription(); |
754 trials[i].stats.ReportTrialResult(increase_ratio); | 750 trials[i].stats.ReportTrialResult(increase_ratio); |
755 } | 751 } |
756 | 752 |
757 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); | 753 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); |
758 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); | 754 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); |
759 } | 755 } |
760 | 756 |
761 } // namespace | 757 } // namespace |
762 } // namespace net | 758 } // namespace net |
OLD | NEW |