diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Region/ClientStack/Linden/UDP/Tests | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/Tests')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs | 272 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs | 174 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs | 104 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/Tests/Resources/4-tile2.jp2 | bin | 0 -> 24410 bytes | |||
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs | 427 |
5 files changed, 977 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs new file mode 100644 index 0000000..a935dd2 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs | |||
@@ -0,0 +1,272 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Net; | ||
30 | using log4net.Config; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenMetaverse.Packets; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Monitoring; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Tests.Common; | ||
39 | |||
40 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// This will contain basic tests for the LindenUDP client stack | ||
44 | /// </summary> | ||
45 | [TestFixture] | ||
46 | public class BasicCircuitTests : OpenSimTestCase | ||
47 | { | ||
48 | private Scene m_scene; | ||
49 | |||
50 | [TestFixtureSetUp] | ||
51 | public void FixtureInit() | ||
52 | { | ||
53 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
54 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; | ||
55 | } | ||
56 | |||
57 | [TestFixtureTearDown] | ||
58 | public void TearDown() | ||
59 | { | ||
60 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
61 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
62 | // tests really shouldn't). | ||
63 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
64 | } | ||
65 | |||
66 | [SetUp] | ||
67 | public override void SetUp() | ||
68 | { | ||
69 | base.SetUp(); | ||
70 | m_scene = new SceneHelpers().SetupScene(); | ||
71 | StatsManager.SimExtraStats = new SimExtraStatsCollector(); | ||
72 | } | ||
73 | |||
74 | // /// <summary> | ||
75 | // /// Build an object name packet for test purposes | ||
76 | // /// </summary> | ||
77 | // /// <param name="objectLocalId"></param> | ||
78 | // /// <param name="objectName"></param> | ||
79 | // private ObjectNamePacket BuildTestObjectNamePacket(uint objectLocalId, string objectName) | ||
80 | // { | ||
81 | // ObjectNamePacket onp = new ObjectNamePacket(); | ||
82 | // ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock(); | ||
83 | // odb.LocalID = objectLocalId; | ||
84 | // odb.Name = Utils.StringToBytes(objectName); | ||
85 | // onp.ObjectData = new ObjectNamePacket.ObjectDataBlock[] { odb }; | ||
86 | // onp.Header.Zerocoded = false; | ||
87 | // | ||
88 | // return onp; | ||
89 | // } | ||
90 | // | ||
91 | /// <summary> | ||
92 | /// Test adding a client to the stack | ||
93 | /// </summary> | ||
94 | [Test] | ||
95 | public void TestAddClient() | ||
96 | { | ||
97 | TestHelpers.InMethod(); | ||
98 | // TestHelpers.EnableLogging(); | ||
99 | |||
100 | TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(m_scene); | ||
101 | |||
102 | UUID myAgentUuid = TestHelpers.ParseTail(0x1); | ||
103 | UUID mySessionUuid = TestHelpers.ParseTail(0x2); | ||
104 | uint myCircuitCode = 123456; | ||
105 | IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999); | ||
106 | |||
107 | UseCircuitCodePacket uccp = new UseCircuitCodePacket(); | ||
108 | |||
109 | UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock | ||
110 | = new UseCircuitCodePacket.CircuitCodeBlock(); | ||
111 | uccpCcBlock.Code = myCircuitCode; | ||
112 | uccpCcBlock.ID = myAgentUuid; | ||
113 | uccpCcBlock.SessionID = mySessionUuid; | ||
114 | uccp.CircuitCode = uccpCcBlock; | ||
115 | |||
116 | byte[] uccpBytes = uccp.ToBytes(); | ||
117 | UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length); | ||
118 | upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor. | ||
119 | Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length); | ||
120 | |||
121 | udpServer.PacketReceived(upb); | ||
122 | |||
123 | // Presence shouldn't exist since the circuit manager doesn't know about this circuit for authentication yet | ||
124 | Assert.That(m_scene.GetScenePresence(myAgentUuid), Is.Null); | ||
125 | |||
126 | AgentCircuitData acd = new AgentCircuitData(); | ||
127 | acd.AgentID = myAgentUuid; | ||
128 | acd.SessionID = mySessionUuid; | ||
129 | |||
130 | m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd); | ||
131 | |||
132 | udpServer.PacketReceived(upb); | ||
133 | |||
134 | // Should succeed now | ||
135 | ScenePresence sp = m_scene.GetScenePresence(myAgentUuid); | ||
136 | Assert.That(sp.UUID, Is.EqualTo(myAgentUuid)); | ||
137 | |||
138 | Assert.That(udpServer.PacketsSent.Count, Is.EqualTo(1)); | ||
139 | |||
140 | Packet packet = udpServer.PacketsSent[0]; | ||
141 | Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket))); | ||
142 | |||
143 | PacketAckPacket ackPacket = packet as PacketAckPacket; | ||
144 | Assert.That(ackPacket.Packets.Length, Is.EqualTo(1)); | ||
145 | Assert.That(ackPacket.Packets[0].ID, Is.EqualTo(0)); | ||
146 | } | ||
147 | |||
148 | [Test] | ||
149 | public void TestLogoutClientDueToAck() | ||
150 | { | ||
151 | TestHelpers.InMethod(); | ||
152 | // TestHelpers.EnableLogging(); | ||
153 | |||
154 | IniConfigSource ics = new IniConfigSource(); | ||
155 | IConfig config = ics.AddConfig("ClientStack.LindenUDP"); | ||
156 | config.Set("AckTimeout", -1); | ||
157 | TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(m_scene, ics); | ||
158 | |||
159 | ScenePresence sp | ||
160 | = ClientStackHelpers.AddChildClient( | ||
161 | m_scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456); | ||
162 | |||
163 | udpServer.ClientOutgoingPacketHandler(sp.ControllingClient, true, false, false); | ||
164 | |||
165 | ScenePresence spAfterAckTimeout = m_scene.GetScenePresence(sp.UUID); | ||
166 | Assert.That(spAfterAckTimeout, Is.Null); | ||
167 | } | ||
168 | |||
169 | // /// <summary> | ||
170 | // /// Test removing a client from the stack | ||
171 | // /// </summary> | ||
172 | // [Test] | ||
173 | // public void TestRemoveClient() | ||
174 | // { | ||
175 | // TestHelper.InMethod(); | ||
176 | // | ||
177 | // uint myCircuitCode = 123457; | ||
178 | // | ||
179 | // TestLLUDPServer testLLUDPServer; | ||
180 | // TestLLPacketServer testLLPacketServer; | ||
181 | // AgentCircuitManager acm; | ||
182 | // SetupStack(new MockScene(), out testLLUDPServer, out testLLPacketServer, out acm); | ||
183 | // AddClient(myCircuitCode, new IPEndPoint(IPAddress.Loopback, 1000), testLLUDPServer, acm); | ||
184 | // | ||
185 | // testLLUDPServer.RemoveClientCircuit(myCircuitCode); | ||
186 | // Assert.IsFalse(testLLUDPServer.HasCircuit(myCircuitCode)); | ||
187 | // | ||
188 | // // Check that removing a non-existent circuit doesn't have any bad effects | ||
189 | // testLLUDPServer.RemoveClientCircuit(101); | ||
190 | // Assert.IsFalse(testLLUDPServer.HasCircuit(101)); | ||
191 | // } | ||
192 | // | ||
193 | // /// <summary> | ||
194 | // /// Make sure that the client stack reacts okay to malformed packets | ||
195 | // /// </summary> | ||
196 | // [Test] | ||
197 | // public void TestMalformedPacketSend() | ||
198 | // { | ||
199 | // TestHelper.InMethod(); | ||
200 | // | ||
201 | // uint myCircuitCode = 123458; | ||
202 | // EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 1001); | ||
203 | // MockScene scene = new MockScene(); | ||
204 | // | ||
205 | // TestLLUDPServer testLLUDPServer; | ||
206 | // TestLLPacketServer testLLPacketServer; | ||
207 | // AgentCircuitManager acm; | ||
208 | // SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm); | ||
209 | // AddClient(myCircuitCode, testEp, testLLUDPServer, acm); | ||
210 | // | ||
211 | // byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04 }; | ||
212 | // | ||
213 | // // Send two garbled 'packets' in succession | ||
214 | // testLLUDPServer.LoadReceive(data, testEp); | ||
215 | // testLLUDPServer.LoadReceive(data, testEp); | ||
216 | // testLLUDPServer.ReceiveData(null); | ||
217 | // | ||
218 | // // Check that we are still here | ||
219 | // Assert.IsTrue(testLLUDPServer.HasCircuit(myCircuitCode)); | ||
220 | // Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(0)); | ||
221 | // | ||
222 | // // Check that sending a valid packet to same circuit still succeeds | ||
223 | // Assert.That(scene.ObjectNameCallsReceived, Is.EqualTo(0)); | ||
224 | // | ||
225 | // testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "helloooo"), testEp); | ||
226 | // testLLUDPServer.ReceiveData(null); | ||
227 | // | ||
228 | // Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(1)); | ||
229 | // Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(1)); | ||
230 | // } | ||
231 | // | ||
232 | // /// <summary> | ||
233 | // /// Test that the stack continues to work even if some client has caused a | ||
234 | // /// SocketException on Socket.BeginReceive() | ||
235 | // /// </summary> | ||
236 | // [Test] | ||
237 | // public void TestExceptionOnBeginReceive() | ||
238 | // { | ||
239 | // TestHelper.InMethod(); | ||
240 | // | ||
241 | // MockScene scene = new MockScene(); | ||
242 | // | ||
243 | // uint circuitCodeA = 130000; | ||
244 | // EndPoint epA = new IPEndPoint(IPAddress.Loopback, 1300); | ||
245 | // UUID agentIdA = UUID.Parse("00000000-0000-0000-0000-000000001300"); | ||
246 | // UUID sessionIdA = UUID.Parse("00000000-0000-0000-0000-000000002300"); | ||
247 | // | ||
248 | // uint circuitCodeB = 130001; | ||
249 | // EndPoint epB = new IPEndPoint(IPAddress.Loopback, 1301); | ||
250 | // UUID agentIdB = UUID.Parse("00000000-0000-0000-0000-000000001301"); | ||
251 | // UUID sessionIdB = UUID.Parse("00000000-0000-0000-0000-000000002301"); | ||
252 | // | ||
253 | // TestLLUDPServer testLLUDPServer; | ||
254 | // TestLLPacketServer testLLPacketServer; | ||
255 | // AgentCircuitManager acm; | ||
256 | // SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm); | ||
257 | // AddClient(circuitCodeA, epA, agentIdA, sessionIdA, testLLUDPServer, acm); | ||
258 | // AddClient(circuitCodeB, epB, agentIdB, sessionIdB, testLLUDPServer, acm); | ||
259 | // | ||
260 | // testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "packet1"), epA); | ||
261 | // testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "packet2"), epB); | ||
262 | // testLLUDPServer.LoadReceiveWithBeginException(epA); | ||
263 | // testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(2, "packet3"), epB); | ||
264 | // testLLUDPServer.ReceiveData(null); | ||
265 | // | ||
266 | // Assert.IsFalse(testLLUDPServer.HasCircuit(circuitCodeA)); | ||
267 | // | ||
268 | // Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(3)); | ||
269 | // Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(3)); | ||
270 | // } | ||
271 | } | ||
272 | } | ||
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs new file mode 100644 index 0000000..6c57e6d --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs | |||
@@ -0,0 +1,174 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Net; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net.Config; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenMetaverse.Packets; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Region.CoreModules.Agent.TextureSender; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Tests.Common; | ||
42 | |||
43 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | ||
44 | { | ||
45 | [TestFixture] | ||
46 | public class LLImageManagerTests : OpenSimTestCase | ||
47 | { | ||
48 | private AssetBase m_testImageAsset; | ||
49 | private Scene scene; | ||
50 | private LLImageManager llim; | ||
51 | private TestClient tc; | ||
52 | |||
53 | [TestFixtureSetUp] | ||
54 | public void FixtureInit() | ||
55 | { | ||
56 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
57 | Util.FireAndForgetMethod = FireAndForgetMethod.None; | ||
58 | |||
59 | using ( | ||
60 | Stream resource | ||
61 | = GetType().Assembly.GetManifestResourceStream( | ||
62 | "OpenSim.Region.ClientStack.LindenUDP.Tests.Resources.4-tile2.jp2")) | ||
63 | { | ||
64 | using (BinaryReader br = new BinaryReader(resource)) | ||
65 | { | ||
66 | m_testImageAsset | ||
67 | = new AssetBase( | ||
68 | TestHelpers.ParseTail(0x1), | ||
69 | "Test Image", | ||
70 | (sbyte)AssetType.Texture, | ||
71 | TestHelpers.ParseTail(0x2).ToString()); | ||
72 | |||
73 | m_testImageAsset.Data = br.ReadBytes(99999999); | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | [TestFixtureTearDown] | ||
79 | public void TearDown() | ||
80 | { | ||
81 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
82 | // threads. Possibly, later tests should be rewritten not to worry about such things. | ||
83 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
84 | } | ||
85 | |||
86 | [SetUp] | ||
87 | public override void SetUp() | ||
88 | { | ||
89 | base.SetUp(); | ||
90 | |||
91 | UUID userId = TestHelpers.ParseTail(0x3); | ||
92 | |||
93 | J2KDecoderModule j2kdm = new J2KDecoderModule(); | ||
94 | |||
95 | SceneHelpers sceneHelpers = new SceneHelpers(); | ||
96 | scene = sceneHelpers.SetupScene(); | ||
97 | SceneHelpers.SetupSceneModules(scene, j2kdm); | ||
98 | |||
99 | tc = new TestClient(SceneHelpers.GenerateAgentData(userId), scene); | ||
100 | llim = new LLImageManager(tc, scene.AssetService, j2kdm); | ||
101 | } | ||
102 | |||
103 | [Test] | ||
104 | public void TestSendImage() | ||
105 | { | ||
106 | TestHelpers.InMethod(); | ||
107 | // XmlConfigurator.Configure(); | ||
108 | |||
109 | scene.AssetService.Store(m_testImageAsset); | ||
110 | |||
111 | TextureRequestArgs args = new TextureRequestArgs(); | ||
112 | args.RequestedAssetID = m_testImageAsset.FullID; | ||
113 | args.DiscardLevel = 0; | ||
114 | args.PacketNumber = 1; | ||
115 | args.Priority = 5; | ||
116 | args.requestSequence = 1; | ||
117 | |||
118 | llim.EnqueueReq(args); | ||
119 | llim.ProcessImageQueue(20); | ||
120 | |||
121 | Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(1)); | ||
122 | } | ||
123 | |||
124 | [Test] | ||
125 | public void TestDiscardImage() | ||
126 | { | ||
127 | TestHelpers.InMethod(); | ||
128 | // XmlConfigurator.Configure(); | ||
129 | |||
130 | scene.AssetService.Store(m_testImageAsset); | ||
131 | |||
132 | TextureRequestArgs args = new TextureRequestArgs(); | ||
133 | args.RequestedAssetID = m_testImageAsset.FullID; | ||
134 | args.DiscardLevel = 0; | ||
135 | args.PacketNumber = 1; | ||
136 | args.Priority = 5; | ||
137 | args.requestSequence = 1; | ||
138 | llim.EnqueueReq(args); | ||
139 | |||
140 | // Now create a discard request | ||
141 | TextureRequestArgs discardArgs = new TextureRequestArgs(); | ||
142 | discardArgs.RequestedAssetID = m_testImageAsset.FullID; | ||
143 | discardArgs.DiscardLevel = -1; | ||
144 | discardArgs.PacketNumber = 1; | ||
145 | discardArgs.Priority = 0; | ||
146 | discardArgs.requestSequence = 2; | ||
147 | llim.EnqueueReq(discardArgs); | ||
148 | |||
149 | llim.ProcessImageQueue(20); | ||
150 | |||
151 | Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0)); | ||
152 | } | ||
153 | |||
154 | [Test] | ||
155 | public void TestMissingImage() | ||
156 | { | ||
157 | TestHelpers.InMethod(); | ||
158 | // XmlConfigurator.Configure(); | ||
159 | |||
160 | TextureRequestArgs args = new TextureRequestArgs(); | ||
161 | args.RequestedAssetID = m_testImageAsset.FullID; | ||
162 | args.DiscardLevel = 0; | ||
163 | args.PacketNumber = 1; | ||
164 | args.Priority = 5; | ||
165 | args.requestSequence = 1; | ||
166 | |||
167 | llim.EnqueueReq(args); | ||
168 | llim.ProcessImageQueue(20); | ||
169 | |||
170 | Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0)); | ||
171 | Assert.That(tc.SentImageNotInDatabasePackets.Count, Is.EqualTo(1)); | ||
172 | } | ||
173 | } | ||
174 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs new file mode 100644 index 0000000..92f1fc3 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using Nini.Config; | ||
29 | using NUnit.Framework; | ||
30 | using OpenMetaverse; | ||
31 | using OpenMetaverse.Packets; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Tests.Common; | ||
34 | |||
35 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Tests for the LL packet handler | ||
39 | /// </summary> | ||
40 | [TestFixture] | ||
41 | public class PacketHandlerTests : OpenSimTestCase | ||
42 | { | ||
43 | // [Test] | ||
44 | // /// <summary> | ||
45 | // /// More a placeholder, really | ||
46 | // /// </summary> | ||
47 | // public void InPacketTest() | ||
48 | // { | ||
49 | // TestHelper.InMethod(); | ||
50 | // | ||
51 | // AgentCircuitData agent = new AgentCircuitData(); | ||
52 | // agent.AgentID = UUID.Random(); | ||
53 | // agent.firstname = "testfirstname"; | ||
54 | // agent.lastname = "testlastname"; | ||
55 | // agent.SessionID = UUID.Zero; | ||
56 | // agent.SecureSessionID = UUID.Zero; | ||
57 | // agent.circuitcode = 123; | ||
58 | // agent.BaseFolder = UUID.Zero; | ||
59 | // agent.InventoryFolder = UUID.Zero; | ||
60 | // agent.startpos = Vector3.Zero; | ||
61 | // agent.CapsPath = "http://wibble.com"; | ||
62 | // | ||
63 | // TestLLUDPServer testLLUDPServer; | ||
64 | // TestLLPacketServer testLLPacketServer; | ||
65 | // AgentCircuitManager acm; | ||
66 | // IScene scene = new MockScene(); | ||
67 | // SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm); | ||
68 | // | ||
69 | // TestClient testClient = new TestClient(agent, scene); | ||
70 | // | ||
71 | // LLPacketHandler packetHandler | ||
72 | // = new LLPacketHandler(testClient, testLLPacketServer, new ClientStackUserSettings()); | ||
73 | // | ||
74 | // packetHandler.InPacket(new AgentAnimationPacket()); | ||
75 | // LLQueItem receivedPacket = packetHandler.PacketQueue.Dequeue(); | ||
76 | // | ||
77 | // Assert.That(receivedPacket, Is.Not.Null); | ||
78 | // Assert.That(receivedPacket.Incoming, Is.True); | ||
79 | // Assert.That(receivedPacket.Packet, Is.TypeOf(typeof(AgentAnimationPacket))); | ||
80 | // } | ||
81 | // | ||
82 | // /// <summary> | ||
83 | // /// Add a client for testing | ||
84 | // /// </summary> | ||
85 | // /// <param name="scene"></param> | ||
86 | // /// <param name="testLLUDPServer"></param> | ||
87 | // /// <param name="testPacketServer"></param> | ||
88 | // /// <param name="acm">Agent circuit manager used in setting up the stack</param> | ||
89 | // protected void SetupStack( | ||
90 | // IScene scene, out TestLLUDPServer testLLUDPServer, out TestLLPacketServer testPacketServer, | ||
91 | // out AgentCircuitManager acm) | ||
92 | // { | ||
93 | // IConfigSource configSource = new IniConfigSource(); | ||
94 | // ClientStackUserSettings userSettings = new ClientStackUserSettings(); | ||
95 | // testLLUDPServer = new TestLLUDPServer(); | ||
96 | // acm = new AgentCircuitManager(); | ||
97 | // | ||
98 | // uint port = 666; | ||
99 | // testLLUDPServer.Initialise(null, ref port, 0, false, configSource, acm); | ||
100 | // testPacketServer = new TestLLPacketServer(testLLUDPServer, userSettings); | ||
101 | // testLLUDPServer.LocalScene = scene; | ||
102 | // } | ||
103 | } | ||
104 | } | ||
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/Resources/4-tile2.jp2 b/OpenSim/Region/ClientStack/Linden/UDP/Tests/Resources/4-tile2.jp2 new file mode 100644 index 0000000..8c63104 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/Resources/4-tile2.jp2 | |||
Binary files differ | |||
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs new file mode 100644 index 0000000..3c82a78 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs | |||
@@ -0,0 +1,427 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using Nini.Config; | ||
30 | using NUnit.Framework; | ||
31 | using OpenMetaverse.Packets; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework.Scenes; | ||
34 | using OpenSim.Tests.Common; | ||
35 | |||
36 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | ||
37 | { | ||
38 | [TestFixture] | ||
39 | public class ThrottleTests : OpenSimTestCase | ||
40 | { | ||
41 | [TestFixtureSetUp] | ||
42 | public void FixtureInit() | ||
43 | { | ||
44 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
45 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; | ||
46 | } | ||
47 | |||
48 | [TestFixtureTearDown] | ||
49 | public void TearDown() | ||
50 | { | ||
51 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
52 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
53 | // tests really shouldn't). | ||
54 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
55 | } | ||
56 | |||
57 | [Test] | ||
58 | public void TestSetRequestDripRate() | ||
59 | { | ||
60 | TestHelpers.InMethod(); | ||
61 | |||
62 | TokenBucket tb = new TokenBucket("tb", null, 5000, 0); | ||
63 | AssertRates(tb, 5000, 0, 5000, 0); | ||
64 | |||
65 | tb.RequestedDripRate = 4000; | ||
66 | AssertRates(tb, 4000, 0, 4000, 0); | ||
67 | |||
68 | tb.RequestedDripRate = 6000; | ||
69 | AssertRates(tb, 6000, 0, 6000, 0); | ||
70 | } | ||
71 | |||
72 | [Test] | ||
73 | public void TestSetRequestDripRateWithMax() | ||
74 | { | ||
75 | TestHelpers.InMethod(); | ||
76 | |||
77 | TokenBucket tb = new TokenBucket("tb", null, 5000, 10000); | ||
78 | AssertRates(tb, 5000, 0, 5000, 10000); | ||
79 | |||
80 | tb.RequestedDripRate = 4000; | ||
81 | AssertRates(tb, 4000, 0, 4000, 10000); | ||
82 | |||
83 | tb.RequestedDripRate = 6000; | ||
84 | AssertRates(tb, 6000, 0, 6000, 10000); | ||
85 | |||
86 | tb.RequestedDripRate = 12000; | ||
87 | AssertRates(tb, 10000, 0, 10000, 10000); | ||
88 | } | ||
89 | |||
90 | [Test] | ||
91 | public void TestSetRequestDripRateWithChildren() | ||
92 | { | ||
93 | TestHelpers.InMethod(); | ||
94 | |||
95 | TokenBucket tbParent = new TokenBucket("tbParent", null, 0, 0); | ||
96 | TokenBucket tbChild1 = new TokenBucket("tbChild1", tbParent, 3000, 0); | ||
97 | TokenBucket tbChild2 = new TokenBucket("tbChild2", tbParent, 5000, 0); | ||
98 | |||
99 | AssertRates(tbParent, 8000, 8000, 8000, 0); | ||
100 | AssertRates(tbChild1, 3000, 0, 3000, 0); | ||
101 | AssertRates(tbChild2, 5000, 0, 5000, 0); | ||
102 | |||
103 | // Test: Setting a parent request greater than total children requests. | ||
104 | tbParent.RequestedDripRate = 10000; | ||
105 | |||
106 | AssertRates(tbParent, 10000, 8000, 8000, 0); | ||
107 | AssertRates(tbChild1, 3000, 0, 3000, 0); | ||
108 | AssertRates(tbChild2, 5000, 0, 5000, 0); | ||
109 | |||
110 | // Test: Setting a parent request lower than total children requests. | ||
111 | tbParent.RequestedDripRate = 6000; | ||
112 | |||
113 | AssertRates(tbParent, 6000, 8000, 6000, 0); | ||
114 | AssertRates(tbChild1, 3000, 0, 6000 / 8 * 3, 0); | ||
115 | AssertRates(tbChild2, 5000, 0, 6000 / 8 * 5, 0); | ||
116 | } | ||
117 | |||
118 | private void AssertRates( | ||
119 | TokenBucket tb, double requestedDripRate, double totalDripRequest, double dripRate, double maxDripRate) | ||
120 | { | ||
121 | Assert.AreEqual((int)requestedDripRate, tb.RequestedDripRate, "Requested drip rate"); | ||
122 | Assert.AreEqual((int)totalDripRequest, tb.TotalDripRequest, "Total drip request"); | ||
123 | Assert.AreEqual((int)dripRate, tb.DripRate, "Drip rate"); | ||
124 | Assert.AreEqual((int)maxDripRate, tb.MaxDripRate, "Max drip rate"); | ||
125 | } | ||
126 | |||
127 | [Test] | ||
128 | public void TestClientThrottleSetNoLimit() | ||
129 | { | ||
130 | TestHelpers.InMethod(); | ||
131 | // TestHelpers.EnableLogging(); | ||
132 | |||
133 | Scene scene = new SceneHelpers().SetupScene(); | ||
134 | TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene); | ||
135 | |||
136 | ScenePresence sp | ||
137 | = ClientStackHelpers.AddChildClient( | ||
138 | scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456); | ||
139 | |||
140 | LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient; | ||
141 | |||
142 | udpServer.Throttle.DebugLevel = 1; | ||
143 | udpClient.ThrottleDebugLevel = 1; | ||
144 | |||
145 | int resendBytes = 1000; | ||
146 | int landBytes = 2000; | ||
147 | int windBytes = 3000; | ||
148 | int cloudBytes = 4000; | ||
149 | int taskBytes = 5000; | ||
150 | int textureBytes = 6000; | ||
151 | int assetBytes = 7000; | ||
152 | |||
153 | SetThrottles( | ||
154 | udpClient, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes); | ||
155 | |||
156 | // We expect this to be lower because of the minimum bound set by MTU | ||
157 | int totalBytes = LLUDPServer.MTU + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes; | ||
158 | |||
159 | AssertThrottles( | ||
160 | udpClient, | ||
161 | LLUDPServer.MTU, landBytes, windBytes, cloudBytes, taskBytes, | ||
162 | textureBytes, assetBytes, totalBytes, 0, 0); | ||
163 | } | ||
164 | |||
165 | [Test] | ||
166 | public void TestClientThrottleAdaptiveNoLimit() | ||
167 | { | ||
168 | TestHelpers.InMethod(); | ||
169 | // TestHelpers.EnableLogging(); | ||
170 | |||
171 | Scene scene = new SceneHelpers().SetupScene(); | ||
172 | |||
173 | IniConfigSource ics = new IniConfigSource(); | ||
174 | IConfig config = ics.AddConfig("ClientStack.LindenUDP"); | ||
175 | config.Set("enable_adaptive_throttles", true); | ||
176 | config.Set("adaptive_throttle_min_bps", 32000); | ||
177 | |||
178 | TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene, ics); | ||
179 | |||
180 | ScenePresence sp | ||
181 | = ClientStackHelpers.AddChildClient( | ||
182 | scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456); | ||
183 | |||
184 | LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient; | ||
185 | |||
186 | udpServer.Throttle.DebugLevel = 1; | ||
187 | udpClient.ThrottleDebugLevel = 1; | ||
188 | |||
189 | // Total is 275000 | ||
190 | int resendBytes = 5000; // this is set low to test the minimum throttle override | ||
191 | int landBytes = 20000; | ||
192 | int windBytes = 30000; | ||
193 | int cloudBytes = 40000; | ||
194 | int taskBytes = 50000; | ||
195 | int textureBytes = 60000; | ||
196 | int assetBytes = 70000; | ||
197 | int totalBytes = resendBytes + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes; | ||
198 | |||
199 | SetThrottles( | ||
200 | udpClient, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes); | ||
201 | |||
202 | // Ratio of current adaptive drip rate to requested bytes, minimum rate is 32000 | ||
203 | double commitRatio = 32000.0 / totalBytes; | ||
204 | |||
205 | AssertThrottles( | ||
206 | udpClient, | ||
207 | LLUDPServer.MTU, landBytes * commitRatio, windBytes * commitRatio, cloudBytes * commitRatio, taskBytes * commitRatio, | ||
208 | textureBytes * commitRatio, assetBytes * commitRatio, udpClient.FlowThrottle.AdjustedDripRate, totalBytes, 0); | ||
209 | |||
210 | // Test an increase in target throttle, ack of 20 packets adds 20 * LLUDPServer.MTU bytes | ||
211 | // to the throttle, recompute commitratio from those numbers | ||
212 | udpClient.FlowThrottle.AcknowledgePackets(20); | ||
213 | commitRatio = (32000.0 + 20.0 * LLUDPServer.MTU) / totalBytes; | ||
214 | |||
215 | AssertThrottles( | ||
216 | udpClient, | ||
217 | LLUDPServer.MTU, landBytes * commitRatio, windBytes * commitRatio, cloudBytes * commitRatio, taskBytes * commitRatio, | ||
218 | textureBytes * commitRatio, assetBytes * commitRatio, udpClient.FlowThrottle.AdjustedDripRate, totalBytes, 0); | ||
219 | |||
220 | // Test a decrease in target throttle, adaptive throttle should cut the rate by 50% with a floor | ||
221 | // set by the minimum adaptive rate | ||
222 | udpClient.FlowThrottle.ExpirePackets(1); | ||
223 | commitRatio = (32000.0 + (20.0 * LLUDPServer.MTU)/Math.Pow(2,1)) / totalBytes; | ||
224 | |||
225 | AssertThrottles( | ||
226 | udpClient, | ||
227 | LLUDPServer.MTU, landBytes * commitRatio, windBytes * commitRatio, cloudBytes * commitRatio, taskBytes * commitRatio, | ||
228 | textureBytes * commitRatio, assetBytes * commitRatio, udpClient.FlowThrottle.AdjustedDripRate, totalBytes, 0); | ||
229 | } | ||
230 | |||
231 | /// <summary> | ||
232 | /// Test throttle setttings where max client throttle has been limited server side. | ||
233 | /// </summary> | ||
234 | [Test] | ||
235 | public void TestSingleClientThrottleRegionLimited() | ||
236 | { | ||
237 | TestHelpers.InMethod(); | ||
238 | // TestHelpers.EnableLogging(); | ||
239 | |||
240 | int resendBytes = 6000; | ||
241 | int landBytes = 8000; | ||
242 | int windBytes = 10000; | ||
243 | int cloudBytes = 12000; | ||
244 | int taskBytes = 14000; | ||
245 | int textureBytes = 16000; | ||
246 | int assetBytes = 18000; | ||
247 | int totalBytes | ||
248 | = (int)((resendBytes + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes) / 2); | ||
249 | |||
250 | Scene scene = new SceneHelpers().SetupScene(); | ||
251 | TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene); | ||
252 | udpServer.Throttle.RequestedDripRate = totalBytes; | ||
253 | |||
254 | ScenePresence sp1 | ||
255 | = ClientStackHelpers.AddChildClient( | ||
256 | scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456); | ||
257 | |||
258 | LLUDPClient udpClient1 = ((LLClientView)sp1.ControllingClient).UDPClient; | ||
259 | |||
260 | SetThrottles( | ||
261 | udpClient1, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes); | ||
262 | |||
263 | AssertThrottles( | ||
264 | udpClient1, | ||
265 | resendBytes / 2, landBytes / 2, windBytes / 2, cloudBytes / 2, taskBytes / 2, | ||
266 | textureBytes / 2, assetBytes / 2, totalBytes, 0, 0); | ||
267 | |||
268 | // Test: Now add another client | ||
269 | ScenePresence sp2 | ||
270 | = ClientStackHelpers.AddChildClient( | ||
271 | scene, udpServer, TestHelpers.ParseTail(0x10), TestHelpers.ParseTail(0x20), 123457); | ||
272 | |||
273 | LLUDPClient udpClient2 = ((LLClientView)sp2.ControllingClient).UDPClient; | ||
274 | // udpClient.ThrottleDebugLevel = 1; | ||
275 | |||
276 | SetThrottles( | ||
277 | udpClient2, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes); | ||
278 | |||
279 | AssertThrottles( | ||
280 | udpClient1, | ||
281 | resendBytes / 4, landBytes / 4, windBytes / 4, cloudBytes / 4, taskBytes / 4, | ||
282 | textureBytes / 4, assetBytes / 4, totalBytes / 2, 0, 0); | ||
283 | |||
284 | AssertThrottles( | ||
285 | udpClient2, | ||
286 | resendBytes / 4, landBytes / 4, windBytes / 4, cloudBytes / 4, taskBytes / 4, | ||
287 | textureBytes / 4, assetBytes / 4, totalBytes / 2, 0, 0); | ||
288 | } | ||
289 | |||
290 | /// <summary> | ||
291 | /// Test throttle setttings where max client throttle has been limited server side. | ||
292 | /// </summary> | ||
293 | [Test] | ||
294 | public void TestClientThrottlePerClientLimited() | ||
295 | { | ||
296 | TestHelpers.InMethod(); | ||
297 | // TestHelpers.EnableLogging(); | ||
298 | |||
299 | int resendBytes = 4000; | ||
300 | int landBytes = 6000; | ||
301 | int windBytes = 8000; | ||
302 | int cloudBytes = 10000; | ||
303 | int taskBytes = 12000; | ||
304 | int textureBytes = 14000; | ||
305 | int assetBytes = 16000; | ||
306 | int totalBytes | ||
307 | = (int)((resendBytes + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes) / 2); | ||
308 | |||
309 | Scene scene = new SceneHelpers().SetupScene(); | ||
310 | TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene); | ||
311 | udpServer.ThrottleRates.Total = totalBytes; | ||
312 | |||
313 | ScenePresence sp | ||
314 | = ClientStackHelpers.AddChildClient( | ||
315 | scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456); | ||
316 | |||
317 | LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient; | ||
318 | // udpClient.ThrottleDebugLevel = 1; | ||
319 | |||
320 | SetThrottles( | ||
321 | udpClient, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes); | ||
322 | |||
323 | AssertThrottles( | ||
324 | udpClient, | ||
325 | resendBytes / 2, landBytes / 2, windBytes / 2, cloudBytes / 2, taskBytes / 2, | ||
326 | textureBytes / 2, assetBytes / 2, totalBytes, 0, totalBytes); | ||
327 | } | ||
328 | |||
329 | [Test] | ||
330 | public void TestClientThrottlePerClientAndRegionLimited() | ||
331 | { | ||
332 | TestHelpers.InMethod(); | ||
333 | //TestHelpers.EnableLogging(); | ||
334 | |||
335 | int resendBytes = 4000; | ||
336 | int landBytes = 6000; | ||
337 | int windBytes = 8000; | ||
338 | int cloudBytes = 10000; | ||
339 | int taskBytes = 12000; | ||
340 | int textureBytes = 14000; | ||
341 | int assetBytes = 16000; | ||
342 | |||
343 | // current total 70000 | ||
344 | int totalBytes = resendBytes + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes; | ||
345 | |||
346 | Scene scene = new SceneHelpers().SetupScene(); | ||
347 | TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene); | ||
348 | udpServer.ThrottleRates.Total = (int)(totalBytes * 1.1); | ||
349 | udpServer.Throttle.RequestedDripRate = (int)(totalBytes * 1.5); | ||
350 | |||
351 | ScenePresence sp1 | ||
352 | = ClientStackHelpers.AddChildClient( | ||
353 | scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456); | ||
354 | |||
355 | LLUDPClient udpClient1 = ((LLClientView)sp1.ControllingClient).UDPClient; | ||
356 | udpClient1.ThrottleDebugLevel = 1; | ||
357 | |||
358 | SetThrottles( | ||
359 | udpClient1, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes); | ||
360 | |||
361 | AssertThrottles( | ||
362 | udpClient1, | ||
363 | resendBytes, landBytes, windBytes, cloudBytes, taskBytes, | ||
364 | textureBytes, assetBytes, totalBytes, 0, totalBytes * 1.1); | ||
365 | |||
366 | // Now add another client | ||
367 | ScenePresence sp2 | ||
368 | = ClientStackHelpers.AddChildClient( | ||
369 | scene, udpServer, TestHelpers.ParseTail(0x10), TestHelpers.ParseTail(0x20), 123457); | ||
370 | |||
371 | LLUDPClient udpClient2 = ((LLClientView)sp2.ControllingClient).UDPClient; | ||
372 | udpClient2.ThrottleDebugLevel = 1; | ||
373 | |||
374 | SetThrottles( | ||
375 | udpClient2, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes); | ||
376 | |||
377 | AssertThrottles( | ||
378 | udpClient1, | ||
379 | resendBytes * 0.75, landBytes * 0.75, windBytes * 0.75, cloudBytes * 0.75, taskBytes * 0.75, | ||
380 | textureBytes * 0.75, assetBytes * 0.75, totalBytes * 0.75, 0, totalBytes * 1.1); | ||
381 | |||
382 | AssertThrottles( | ||
383 | udpClient2, | ||
384 | resendBytes * 0.75, landBytes * 0.75, windBytes * 0.75, cloudBytes * 0.75, taskBytes * 0.75, | ||
385 | textureBytes * 0.75, assetBytes * 0.75, totalBytes * 0.75, 0, totalBytes * 1.1); | ||
386 | } | ||
387 | |||
388 | private void AssertThrottles( | ||
389 | LLUDPClient udpClient, | ||
390 | double resendBytes, double landBytes, double windBytes, double cloudBytes, double taskBytes, double textureBytes, double assetBytes, | ||
391 | double totalBytes, double targetBytes, double maxBytes) | ||
392 | { | ||
393 | ClientInfo ci = udpClient.GetClientInfo(); | ||
394 | |||
395 | // Console.WriteLine( | ||
396 | // "Resend={0}, Land={1}, Wind={2}, Cloud={3}, Task={4}, Texture={5}, Asset={6}, TOTAL = {7}", | ||
397 | // ci.resendThrottle, ci.landThrottle, ci.windThrottle, ci.cloudThrottle, ci.taskThrottle, ci.textureThrottle, ci.assetThrottle, ci.totalThrottle); | ||
398 | |||
399 | Assert.AreEqual((int)resendBytes, ci.resendThrottle, "Resend"); | ||
400 | Assert.AreEqual((int)landBytes, ci.landThrottle, "Land"); | ||
401 | Assert.AreEqual((int)windBytes, ci.windThrottle, "Wind"); | ||
402 | Assert.AreEqual((int)cloudBytes, ci.cloudThrottle, "Cloud"); | ||
403 | Assert.AreEqual((int)taskBytes, ci.taskThrottle, "Task"); | ||
404 | Assert.AreEqual((int)textureBytes, ci.textureThrottle, "Texture"); | ||
405 | Assert.AreEqual((int)assetBytes, ci.assetThrottle, "Asset"); | ||
406 | Assert.AreEqual((int)totalBytes, ci.totalThrottle, "Total"); | ||
407 | Assert.AreEqual((int)targetBytes, ci.targetThrottle, "Target"); | ||
408 | Assert.AreEqual((int)maxBytes, ci.maxThrottle, "Max"); | ||
409 | } | ||
410 | |||
411 | private void SetThrottles( | ||
412 | LLUDPClient udpClient, int resendBytes, int landBytes, int windBytes, int cloudBytes, int taskBytes, int textureBytes, int assetBytes) | ||
413 | { | ||
414 | byte[] throttles = new byte[28]; | ||
415 | |||
416 | Array.Copy(BitConverter.GetBytes((float)resendBytes * 8), 0, throttles, 0, 4); | ||
417 | Array.Copy(BitConverter.GetBytes((float)landBytes * 8), 0, throttles, 4, 4); | ||
418 | Array.Copy(BitConverter.GetBytes((float)windBytes * 8), 0, throttles, 8, 4); | ||
419 | Array.Copy(BitConverter.GetBytes((float)cloudBytes * 8), 0, throttles, 12, 4); | ||
420 | Array.Copy(BitConverter.GetBytes((float)taskBytes * 8), 0, throttles, 16, 4); | ||
421 | Array.Copy(BitConverter.GetBytes((float)textureBytes * 8), 0, throttles, 20, 4); | ||
422 | Array.Copy(BitConverter.GetBytes((float)assetBytes * 8), 0, throttles, 24, 4); | ||
423 | |||
424 | udpClient.SetThrottles(throttles); | ||
425 | } | ||
426 | } | ||
427 | } \ No newline at end of file | ||