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 <vector> | 17 #include <vector> |
18 | 18 |
19 #include "base/environment.h" | 19 #include "base/environment.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/memory/scoped_vector.h" | |
22 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
23 #include "base/time/time.h" | 22 #include "base/time/time.h" |
24 #include "net/base/request_priority.h" | 23 #include "net/base/request_priority.h" |
25 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
26 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
27 #include "net/url_request/url_request_test_util.h" | 26 #include "net/url_request/url_request_test_util.h" |
28 #include "net/url_request/url_request_throttler_manager.h" | 27 #include "net/url_request/url_request_throttler_manager.h" |
29 #include "net/url_request/url_request_throttler_test_support.h" | 28 #include "net/url_request/url_request_throttler_test_support.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
31 | 30 |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 }; | 481 }; |
483 | 482 |
484 void SimulateAttack(Server* server, | 483 void SimulateAttack(Server* server, |
485 RequesterResults* attacker_results, | 484 RequesterResults* attacker_results, |
486 RequesterResults* client_results, | 485 RequesterResults* client_results, |
487 bool enable_throttling) { | 486 bool enable_throttling) { |
488 const size_t kNumAttackers = 50; | 487 const size_t kNumAttackers = 50; |
489 const size_t kNumClients = 50; | 488 const size_t kNumClients = 50; |
490 DiscreteTimeSimulation simulation; | 489 DiscreteTimeSimulation simulation; |
491 URLRequestThrottlerManager manager; | 490 URLRequestThrottlerManager manager; |
492 ScopedVector<Requester> requesters; | 491 std::vector<scoped_ptr<Requester>> requesters; |
mmenke
2015/11/24 17:39:33
This change really doesn't seem to belong in this
| |
493 for (size_t i = 0; i < kNumAttackers; ++i) { | 492 for (size_t i = 0; i < kNumAttackers; ++i) { |
494 // Use a tiny time_between_requests so the attackers will ping the | 493 // Use a tiny time_between_requests so the attackers will ping the |
495 // server at every tick of the simulation. | 494 // server at every tick of the simulation. |
496 scoped_refptr<MockURLRequestThrottlerEntry> throttler_entry( | 495 scoped_refptr<MockURLRequestThrottlerEntry> throttler_entry( |
497 new MockURLRequestThrottlerEntry(&manager)); | 496 new MockURLRequestThrottlerEntry(&manager)); |
498 if (!enable_throttling) | 497 if (!enable_throttling) |
499 throttler_entry->DisableBackoffThrottling(); | 498 throttler_entry->DisableBackoffThrottling(); |
500 | 499 |
501 Requester* attacker = new Requester(throttler_entry.get(), | 500 scoped_ptr<Requester> attacker(new Requester(throttler_entry.get(), |
502 TimeDelta::FromMilliseconds(1), | 501 TimeDelta::FromMilliseconds(1), |
503 server, | 502 server, attacker_results)); |
504 attacker_results); | |
505 attacker->SetStartupJitter(TimeDelta::FromSeconds(120)); | 503 attacker->SetStartupJitter(TimeDelta::FromSeconds(120)); |
506 requesters.push_back(attacker); | 504 simulation.AddActor(attacker.get()); |
507 simulation.AddActor(attacker); | 505 requesters.push_back(std::move(attacker)); |
508 } | 506 } |
509 for (size_t i = 0; i < kNumClients; ++i) { | 507 for (size_t i = 0; i < kNumClients; ++i) { |
510 // Normal clients only make requests every 2 minutes, plus/minus 1 minute. | 508 // Normal clients only make requests every 2 minutes, plus/minus 1 minute. |
511 scoped_refptr<MockURLRequestThrottlerEntry> throttler_entry( | 509 scoped_refptr<MockURLRequestThrottlerEntry> throttler_entry( |
512 new MockURLRequestThrottlerEntry(&manager)); | 510 new MockURLRequestThrottlerEntry(&manager)); |
513 if (!enable_throttling) | 511 if (!enable_throttling) |
514 throttler_entry->DisableBackoffThrottling(); | 512 throttler_entry->DisableBackoffThrottling(); |
515 | 513 |
516 Requester* client = new Requester(throttler_entry.get(), | 514 scoped_ptr<Requester> client(new Requester(throttler_entry.get(), |
517 TimeDelta::FromMinutes(2), | 515 TimeDelta::FromMinutes(2), |
518 server, | 516 server, client_results)); |
519 client_results); | |
520 client->SetStartupJitter(TimeDelta::FromSeconds(120)); | 517 client->SetStartupJitter(TimeDelta::FromSeconds(120)); |
521 client->SetRequestJitter(TimeDelta::FromMinutes(1)); | 518 client->SetRequestJitter(TimeDelta::FromMinutes(1)); |
522 requesters.push_back(client); | 519 simulation.AddActor(client.get()); |
523 simulation.AddActor(client); | 520 requesters.push_back(std::move(client)); |
524 } | 521 } |
525 simulation.AddActor(server); | 522 simulation.AddActor(server); |
526 | 523 |
527 simulation.RunSimulation(TimeDelta::FromMinutes(6), | 524 simulation.RunSimulation(TimeDelta::FromMinutes(6), |
528 TimeDelta::FromSeconds(1)); | 525 TimeDelta::FromSeconds(1)); |
529 } | 526 } |
530 | 527 |
531 TEST(URLRequestThrottlerSimulation, HelpsInAttack) { | 528 TEST(URLRequestThrottlerSimulation, HelpsInAttack) { |
532 Server unprotected_server(30, 1.0); | 529 Server unprotected_server(30, 1.0); |
533 RequesterResults unprotected_attacker_results; | 530 RequesterResults unprotected_attacker_results; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 trials[i].PrintTrialDescription(); | 737 trials[i].PrintTrialDescription(); |
741 trials[i].stats.ReportTrialResult(increase_ratio); | 738 trials[i].stats.ReportTrialResult(increase_ratio); |
742 } | 739 } |
743 | 740 |
744 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); | 741 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); |
745 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); | 742 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); |
746 } | 743 } |
747 | 744 |
748 } // namespace | 745 } // namespace |
749 } // namespace net | 746 } // namespace net |
OLD | NEW |