aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs
blob: 83d5b5f50b6c6431d8321841119e131fb67f6c85 (plain)
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
/*
 * 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 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 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;
//            udpClient.ThrottleDebugLevel = 1;

            byte[] throttles = new byte[28];
            float resendBits = 10000;
            float landBits = 20000;
            float windBits = 30000;
            float cloudBits = 40000;
            float taskBits = 50000;
            float textureBits = 60000;
            float assetBits = 70000;

            Array.Copy(BitConverter.GetBytes(resendBits), 0, throttles, 0, 4);
            Array.Copy(BitConverter.GetBytes(landBits), 0, throttles, 4, 4);
            Array.Copy(BitConverter.GetBytes(windBits), 0, throttles, 8, 4);
            Array.Copy(BitConverter.GetBytes(cloudBits), 0, throttles, 12, 4);
            Array.Copy(BitConverter.GetBytes(taskBits), 0, throttles, 16, 4);
            Array.Copy(BitConverter.GetBytes(textureBits), 0, throttles, 20, 4);
            Array.Copy(BitConverter.GetBytes(assetBits), 0, throttles, 24, 4);

//            Console.WriteLine(BitConverter.ToString(throttles));

            udpClient.SetThrottles(throttles);
            ClientInfo ci = udpClient.GetClientInfo();

            // We expect this to be lower because of the minimum bound set by MTU
            float totalBits = LLUDPServer.MTU * 8 + landBits + windBits + cloudBits + taskBits + textureBits + assetBits;
            Assert.AreEqual(LLUDPServer.MTU, ci.resendThrottle);
            Assert.AreEqual(landBits / 8, ci.landThrottle);
            Assert.AreEqual(windBits / 8, ci.windThrottle);
            Assert.AreEqual(cloudBits / 8, ci.cloudThrottle);
            Assert.AreEqual(taskBits / 8, ci.taskThrottle);
            Assert.AreEqual(textureBits / 8, ci.textureThrottle);
            Assert.AreEqual(assetBits / 8, ci.assetThrottle);
            Assert.AreEqual(totalBits / 8, ci.totalThrottle);
        }
    }
}