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_vector.h" | 20 #include "base/memory/scoped_vector.h" |
21 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "net/base/request_priority.h" |
23 #include "net/url_request/url_request_test_util.h" | 24 #include "net/url_request/url_request_test_util.h" |
24 #include "net/url_request/url_request_throttler_manager.h" | 25 #include "net/url_request/url_request_throttler_manager.h" |
25 #include "net/url_request/url_request_throttler_test_support.h" | 26 #include "net/url_request/url_request_throttler_test_support.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 | 28 |
28 using base::TimeDelta; | 29 using base::TimeDelta; |
29 using base::TimeTicks; | 30 using base::TimeTicks; |
30 | 31 |
31 namespace net { | 32 namespace net { |
32 namespace { | 33 namespace { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 std::vector<Actor*> actors_; | 110 std::vector<Actor*> actors_; |
110 | 111 |
111 DISALLOW_COPY_AND_ASSIGN(DiscreteTimeSimulation); | 112 DISALLOW_COPY_AND_ASSIGN(DiscreteTimeSimulation); |
112 }; | 113 }; |
113 | 114 |
114 // Represents a web server in a simulation of a server under attack by | 115 // Represents a web server in a simulation of a server under attack by |
115 // a lot of clients. Must be added to the simulation's list of actors | 116 // a lot of clients. Must be added to the simulation's list of actors |
116 // after all |Requester| objects. | 117 // after all |Requester| objects. |
117 class Server : public DiscreteTimeSimulation::Actor { | 118 class Server : public DiscreteTimeSimulation::Actor { |
118 public: | 119 public: |
119 Server(int max_queries_per_tick, | 120 Server(int max_queries_per_tick, 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, &context_, NULL) { | 127 mock_request_(GURL(), DEFAULT_PRIORITY, NULL, &context_) {} |
128 } | |
129 | 128 |
130 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { | 129 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { |
131 start_downtime_ = start_time; | 130 start_downtime_ = start_time; |
132 end_downtime_ = start_time + duration; | 131 end_downtime_ = start_time + duration; |
133 } | 132 } |
134 | 133 |
135 virtual void AdvanceTime(const TimeTicks& absolute_time) OVERRIDE { | 134 virtual void AdvanceTime(const TimeTicks& absolute_time) OVERRIDE { |
136 now_ = absolute_time; | 135 now_ = absolute_time; |
137 } | 136 } |
138 | 137 |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 trials[i].PrintTrialDescription(); | 745 trials[i].PrintTrialDescription(); |
747 trials[i].stats.ReportTrialResult(increase_ratio); | 746 trials[i].stats.ReportTrialResult(increase_ratio); |
748 } | 747 } |
749 | 748 |
750 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); | 749 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); |
751 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); | 750 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); |
752 } | 751 } |
753 | 752 |
754 } // namespace | 753 } // namespace |
755 } // namespace net | 754 } // namespace net |
OLD | NEW |