1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using Nini.Config;
using NUnit.Framework;
using OpenMetaverse.Packets;
using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Tests.Common;
namespace OpenSim.Region.ClientStack.LindenUDP.Tests
{
[TestFixture]
public class ThrottleTests : OpenSimTestCase
{
[TestFixtureSetUp]
public void FixtureInit()
{
// Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
}
[TestFixtureTearDown]
public void TearDown()
{
// We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
// threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
// tests really shouldn't).
Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
}
[Test]
public void TestSetRequestDripRate()
{
TokenBucket tb = new TokenBucket("tb", null, 5000, 0);
AssertRates(tb, 5000, 5000, 5000, 0);
tb.RequestedDripRate = 4000;
AssertRates(tb, 4000, 4000, 4000, 0);
tb.RequestedDripRate = 6000;
AssertRates(tb, 6000, 6000, 6000, 0);
}
[Test]
public void TestSetRequestDripRateWithMax()
{
TokenBucket tb = new TokenBucket("tb", null, 5000, 10000);
AssertRates(tb, 5000, 5000, 5000, 10000);
tb.RequestedDripRate = 4000;
AssertRates(tb, 4000, 4000, 4000, 10000);
tb.RequestedDripRate = 6000;
AssertRates(tb, 6000, 6000, 6000, 10000);
tb.RequestedDripRate = 12000;
AssertRates(tb, 10000, 10000, 10000, 10000);
}
[Test]
public void TestSetRequestDripRateWithChildren()
{
TokenBucket tbParent = new TokenBucket("tbParent", null, 0, 0);
TokenBucket tbChild1 = new TokenBucket("tbChild1", tbParent, 3000, 0);
TokenBucket tbChild2 = new TokenBucket("tbChild2", tbParent, 5000, 0);
AssertRates(tbParent, 8000, 8000, 8000, 0);
AssertRates(tbChild1, 3000, 3000, 3000, 0);
AssertRates(tbChild2, 5000, 5000, 5000, 0);
}
private void AssertRates(
TokenBucket tb, double requestedDripRate, double totalDripRequest, double dripRate, double maxDripRate)
{
Assert.AreEqual((int)requestedDripRate, tb.RequestedDripRate);
Assert.AreEqual((int)totalDripRequest, tb.TotalDripRequest);
Assert.AreEqual((int)dripRate, tb.DripRate);
Assert.AreEqual((int)maxDripRate, tb.MaxDripRate);
}
[Test]
public void TestClientThrottleSetNoLimit()
{
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
Scene scene = new SceneHelpers().SetupScene();
TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene);
ScenePresence sp
= ClientStackHelpers.AddChildClient(
scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456);
LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient;
udpServer.Throttle.DebugLevel = 1;
udpClient.ThrottleDebugLevel = 1;
int resendBytes = 1000;
int landBytes = 2000;
int windBytes = 3000;
int cloudBytes = 4000;
int taskBytes = 5000;
int textureBytes = 6000;
int assetBytes = 7000;
SetThrottles(
udpClient, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes);
// We expect this to be lower because of the minimum bound set by MTU
int totalBytes = LLUDPServer.MTU + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes;
AssertThrottles(
udpClient,
LLUDPServer.MTU, landBytes, windBytes, cloudBytes, taskBytes,
textureBytes, assetBytes, totalBytes, 0, 0);
}
[Test]
public void TestClientThrottleAdaptiveNoLimit()
{
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
Scene scene = new SceneHelpers().SetupScene();
IniConfigSource ics = new IniConfigSource();
IConfig config = ics.AddConfig("ClientStack.LindenUDP");
config.Set("enable_adaptive_throttles", true);
TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene, ics);
ScenePresence sp
= ClientStackHelpers.AddChildClient(
scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456);
LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient;
udpServer.Throttle.DebugLevel = 1;
udpClient.ThrottleDebugLevel = 1;
// Total is 28000
int resendBytes = 10000;
int landBytes = 20000;
int windBytes = 30000;
int cloudBytes = 40000;
int taskBytes = 50000;
int textureBytes = 60000;
int assetBytes = 70000;
SetThrottles(
udpClient, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes);
// We expect individual throttle changes to currently have no effect under adaptive, since this is managed
// purely by that throttle. However, we expect the max to change.
// XXX: At the moment we check against defaults, but at some point there should be a better test to
// active see change over time.
ThrottleRates defaultRates = udpServer.ThrottleRates;
// Current total is 66750
int totalBytes = defaultRates.Resend + defaultRates.Land + defaultRates.Wind + defaultRates.Cloud + defaultRates.Task + defaultRates.Texture + defaultRates.Asset;
int totalMaxBytes = resendBytes + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes;
AssertThrottles(
udpClient,
defaultRates.Resend, defaultRates.Land, defaultRates.Wind, defaultRates.Cloud, defaultRates.Task,
defaultRates.Texture, defaultRates.Asset, totalBytes, totalMaxBytes, 0);
}
/// <summary>
/// Test throttle setttings where max client throttle has been limited server side.
/// </summary>
[Test]
public void TestSingleClientThrottleRegionLimited()
{
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
int resendBytes = 6000;
int landBytes = 8000;
int windBytes = 10000;
int cloudBytes = 12000;
int taskBytes = 14000;
int textureBytes = 16000;
int assetBytes = 18000;
int totalBytes
= (int)((resendBytes + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes) / 2);
Scene scene = new SceneHelpers().SetupScene();
TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene);
udpServer.Throttle.RequestedDripRate = totalBytes;
ScenePresence sp1
= ClientStackHelpers.AddChildClient(
scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456);
LLUDPClient udpClient1 = ((LLClientView)sp1.ControllingClient).UDPClient;
SetThrottles(
udpClient1, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes);
AssertThrottles(
udpClient1,
resendBytes / 2, landBytes / 2, windBytes / 2, cloudBytes / 2, taskBytes / 2,
textureBytes / 2, assetBytes / 2, totalBytes, 0, 0);
// Test: Now add another client
ScenePresence sp2
= ClientStackHelpers.AddChildClient(
scene, udpServer, TestHelpers.ParseTail(0x10), TestHelpers.ParseTail(0x20), 123457);
LLUDPClient udpClient2 = ((LLClientView)sp2.ControllingClient).UDPClient;
// udpClient.ThrottleDebugLevel = 1;
SetThrottles(
udpClient2, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes);
AssertThrottles(
udpClient1,
resendBytes / 4, landBytes / 4, windBytes / 4, cloudBytes / 4, taskBytes / 4,
textureBytes / 4, assetBytes / 4, totalBytes / 2, 0, 0);
AssertThrottles(
udpClient2,
resendBytes / 4, landBytes / 4, windBytes / 4, cloudBytes / 4, taskBytes / 4,
textureBytes / 4, assetBytes / 4, totalBytes / 2, 0, 0);
}
/// <summary>
/// Test throttle setttings where max client throttle has been limited server side.
/// </summary>
[Test]
public void TestClientThrottlePerClientLimited()
{
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
int resendBytes = 4000;
int landBytes = 6000;
int windBytes = 8000;
int cloudBytes = 10000;
int taskBytes = 12000;
int textureBytes = 14000;
int assetBytes = 16000;
int totalBytes
= (int)((resendBytes + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes) / 2);
Scene scene = new SceneHelpers().SetupScene();
TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene);
udpServer.ThrottleRates.Total = totalBytes;
ScenePresence sp
= ClientStackHelpers.AddChildClient(
scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456);
LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient;
// udpClient.ThrottleDebugLevel = 1;
SetThrottles(
udpClient, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes);
AssertThrottles(
udpClient,
resendBytes / 2, landBytes / 2, windBytes / 2, cloudBytes / 2, taskBytes / 2,
textureBytes / 2, assetBytes / 2, totalBytes, 0, totalBytes);
}
[Test]
public void TestClientThrottlePerClientAndRegionLimited()
{
TestHelpers.InMethod();
//TestHelpers.EnableLogging();
int resendBytes = 4000;
int landBytes = 6000;
int windBytes = 8000;
int cloudBytes = 10000;
int taskBytes = 12000;
int textureBytes = 14000;
int assetBytes = 16000;
// current total 70000
int totalBytes = resendBytes + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes;
Scene scene = new SceneHelpers().SetupScene();
TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene);
udpServer.ThrottleRates.Total = (int)(totalBytes * 1.1);
udpServer.Throttle.RequestedDripRate = (int)(totalBytes * 1.5);
ScenePresence sp1
= ClientStackHelpers.AddChildClient(
scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456);
LLUDPClient udpClient1 = ((LLClientView)sp1.ControllingClient).UDPClient;
udpClient1.ThrottleDebugLevel = 1;
SetThrottles(
udpClient1, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes);
AssertThrottles(
udpClient1,
resendBytes, landBytes, windBytes, cloudBytes, taskBytes,
textureBytes, assetBytes, totalBytes, 0, totalBytes * 1.1);
// Now add another client
ScenePresence sp2
= ClientStackHelpers.AddChildClient(
scene, udpServer, TestHelpers.ParseTail(0x10), TestHelpers.ParseTail(0x20), 123457);
LLUDPClient udpClient2 = ((LLClientView)sp2.ControllingClient).UDPClient;
udpClient2.ThrottleDebugLevel = 1;
SetThrottles(
udpClient2, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes);
AssertThrottles(
udpClient1,
resendBytes * 0.75, landBytes * 0.75, windBytes * 0.75, cloudBytes * 0.75, taskBytes * 0.75,
textureBytes * 0.75, assetBytes * 0.75, totalBytes * 0.75, 0, totalBytes * 1.1);
AssertThrottles(
udpClient2,
resendBytes * 0.75, landBytes * 0.75, windBytes * 0.75, cloudBytes * 0.75, taskBytes * 0.75,
textureBytes * 0.75, assetBytes * 0.75, totalBytes * 0.75, 0, totalBytes * 1.1);
}
private void AssertThrottles(
LLUDPClient udpClient,
double resendBytes, double landBytes, double windBytes, double cloudBytes, double taskBytes, double textureBytes, double assetBytes,
double totalBytes, double targetBytes, double maxBytes)
{
ClientInfo ci = udpClient.GetClientInfo();
// Console.WriteLine(
// "Resend={0}, Land={1}, Wind={2}, Cloud={3}, Task={4}, Texture={5}, Asset={6}, TOTAL = {7}",
// ci.resendThrottle, ci.landThrottle, ci.windThrottle, ci.cloudThrottle, ci.taskThrottle, ci.textureThrottle, ci.assetThrottle, ci.totalThrottle);
Assert.AreEqual((int)resendBytes, ci.resendThrottle);
Assert.AreEqual((int)landBytes, ci.landThrottle);
Assert.AreEqual((int)windBytes, ci.windThrottle);
Assert.AreEqual((int)cloudBytes, ci.cloudThrottle);
Assert.AreEqual((int)taskBytes, ci.taskThrottle);
Assert.AreEqual((int)textureBytes, ci.textureThrottle);
Assert.AreEqual((int)assetBytes, ci.assetThrottle);
Assert.AreEqual((int)totalBytes, ci.totalThrottle);
Assert.AreEqual((int)targetBytes, ci.targetThrottle);
Assert.AreEqual((int)maxBytes, ci.maxThrottle);
}
private void SetThrottles(
LLUDPClient udpClient, int resendBytes, int landBytes, int windBytes, int cloudBytes, int taskBytes, int textureBytes, int assetBytes)
{
byte[] throttles = new byte[28];
Array.Copy(BitConverter.GetBytes((float)resendBytes * 8), 0, throttles, 0, 4);
Array.Copy(BitConverter.GetBytes((float)landBytes * 8), 0, throttles, 4, 4);
Array.Copy(BitConverter.GetBytes((float)windBytes * 8), 0, throttles, 8, 4);
Array.Copy(BitConverter.GetBytes((float)cloudBytes * 8), 0, throttles, 12, 4);
Array.Copy(BitConverter.GetBytes((float)taskBytes * 8), 0, throttles, 16, 4);
Array.Copy(BitConverter.GetBytes((float)textureBytes * 8), 0, throttles, 20, 4);
Array.Copy(BitConverter.GetBytes((float)assetBytes * 8), 0, throttles, 24, 4);
udpClient.SetThrottles(throttles);
}
}
}
|