From 134f86e8d5c414409631b25b8c6f0ee45fbd8631 Mon Sep 17 00:00:00 2001
From: David Walter Seikel
Date: Thu, 3 Nov 2016 21:44:39 +1000
Subject: Initial update to OpenSim 0.8.2.1 source code.
---
.../Linden/UDP/Tests/BasicCircuitTests.cs | 110 ++----
.../Linden/UDP/Tests/LLImageManagerTests.cs | 17 +-
.../ClientStack/Linden/UDP/Tests/MockScene.cs | 78 ----
.../Linden/UDP/Tests/PacketHandlerTests.cs | 1 -
.../Linden/UDP/Tests/TestLLUDPServer.cs | 170 --------
.../ClientStack/Linden/UDP/Tests/ThrottleTests.cs | 427 +++++++++++++++++++++
6 files changed, 473 insertions(+), 330 deletions(-)
delete mode 100644 OpenSim/Region/ClientStack/Linden/UDP/Tests/MockScene.cs
delete mode 100644 OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs
create mode 100644 OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs
(limited to 'OpenSim/Region/ClientStack/Linden/UDP/Tests')
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
index 556df30..a935dd2 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
@@ -33,9 +33,9 @@ using NUnit.Framework;
using OpenMetaverse;
using OpenMetaverse.Packets;
using OpenSim.Framework;
+using OpenSim.Framework.Monitoring;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Tests.Common;
-using OpenSim.Tests.Common.Mock;
namespace OpenSim.Region.ClientStack.LindenUDP.Tests
{
@@ -46,7 +46,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
public class BasicCircuitTests : OpenSimTestCase
{
private Scene m_scene;
- private TestLLUDPServer m_udpServer;
[TestFixtureSetUp]
public void FixtureInit()
@@ -69,74 +68,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
{
base.SetUp();
m_scene = new SceneHelpers().SetupScene();
+ StatsManager.SimExtraStats = new SimExtraStatsCollector();
}
- ///
- /// Build an object name packet for test purposes
- ///
- ///
- ///
- private ObjectNamePacket BuildTestObjectNamePacket(uint objectLocalId, string objectName)
- {
- ObjectNamePacket onp = new ObjectNamePacket();
- ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock();
- odb.LocalID = objectLocalId;
- odb.Name = Utils.StringToBytes(objectName);
- onp.ObjectData = new ObjectNamePacket.ObjectDataBlock[] { odb };
- onp.Header.Zerocoded = false;
-
- return onp;
- }
-
- private void AddUdpServer()
- {
- AddUdpServer(new IniConfigSource());
- }
-
- private void AddUdpServer(IniConfigSource configSource)
- {
- uint port = 0;
- AgentCircuitManager acm = m_scene.AuthenticateHandler;
-
- m_udpServer = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, configSource, acm);
- m_udpServer.AddScene(m_scene);
- }
-
- ///
- /// Used by tests that aren't testing this stage.
- ///
- private ScenePresence AddClient()
- {
- UUID myAgentUuid = TestHelpers.ParseTail(0x1);
- UUID mySessionUuid = TestHelpers.ParseTail(0x2);
- uint myCircuitCode = 123456;
- IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
-
- UseCircuitCodePacket uccp = new UseCircuitCodePacket();
-
- UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
- = new UseCircuitCodePacket.CircuitCodeBlock();
- uccpCcBlock.Code = myCircuitCode;
- uccpCcBlock.ID = myAgentUuid;
- uccpCcBlock.SessionID = mySessionUuid;
- uccp.CircuitCode = uccpCcBlock;
-
- byte[] uccpBytes = uccp.ToBytes();
- UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length);
- upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
- Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
-
- AgentCircuitData acd = new AgentCircuitData();
- acd.AgentID = myAgentUuid;
- acd.SessionID = mySessionUuid;
-
- m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd);
-
- m_udpServer.PacketReceived(upb);
-
- return m_scene.GetScenePresence(myAgentUuid);
- }
-
+// ///
+// /// Build an object name packet for test purposes
+// ///
+// ///
+// ///
+// private ObjectNamePacket BuildTestObjectNamePacket(uint objectLocalId, string objectName)
+// {
+// ObjectNamePacket onp = new ObjectNamePacket();
+// ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock();
+// odb.LocalID = objectLocalId;
+// odb.Name = Utils.StringToBytes(objectName);
+// onp.ObjectData = new ObjectNamePacket.ObjectDataBlock[] { odb };
+// onp.Header.Zerocoded = false;
+//
+// return onp;
+// }
+//
///
/// Test adding a client to the stack
///
@@ -146,7 +97,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
- AddUdpServer();
+ TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(m_scene);
UUID myAgentUuid = TestHelpers.ParseTail(0x1);
UUID mySessionUuid = TestHelpers.ParseTail(0x2);
@@ -167,7 +118,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
- m_udpServer.PacketReceived(upb);
+ udpServer.PacketReceived(upb);
// Presence shouldn't exist since the circuit manager doesn't know about this circuit for authentication yet
Assert.That(m_scene.GetScenePresence(myAgentUuid), Is.Null);
@@ -178,15 +129,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd);
- m_udpServer.PacketReceived(upb);
+ udpServer.PacketReceived(upb);
// Should succeed now
ScenePresence sp = m_scene.GetScenePresence(myAgentUuid);
Assert.That(sp.UUID, Is.EqualTo(myAgentUuid));
- Assert.That(m_udpServer.PacketsSent.Count, Is.EqualTo(1));
+ Assert.That(udpServer.PacketsSent.Count, Is.EqualTo(1));
- Packet packet = m_udpServer.PacketsSent[0];
+ Packet packet = udpServer.PacketsSent[0];
Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket)));
PacketAckPacket ackPacket = packet as PacketAckPacket;
@@ -203,15 +154,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
IniConfigSource ics = new IniConfigSource();
IConfig config = ics.AddConfig("ClientStack.LindenUDP");
config.Set("AckTimeout", -1);
- AddUdpServer(ics);
+ TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(m_scene, ics);
+
+ ScenePresence sp
+ = ClientStackHelpers.AddChildClient(
+ m_scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456);
- ScenePresence sp = AddClient();
- m_udpServer.ClientOutgoingPacketHandler(sp.ControllingClient, true, false, false);
+ udpServer.ClientOutgoingPacketHandler(sp.ControllingClient, true, false, false);
ScenePresence spAfterAckTimeout = m_scene.GetScenePresence(sp.UUID);
Assert.That(spAfterAckTimeout, Is.Null);
-
-// TestHelpers.DisableLogging();
}
// ///
@@ -233,7 +185,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
// testLLUDPServer.RemoveClientCircuit(myCircuitCode);
// Assert.IsFalse(testLLUDPServer.HasCircuit(myCircuitCode));
//
-// // Check that removing a non-existant circuit doesn't have any bad effects
+// // Check that removing a non-existent circuit doesn't have any bad effects
// testLLUDPServer.RemoveClientCircuit(101);
// Assert.IsFalse(testLLUDPServer.HasCircuit(101));
// }
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs
index 7d9f581..6c57e6d 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/LLImageManagerTests.cs
@@ -29,6 +29,7 @@ using System;
using System.IO;
using System.Net;
using System.Reflection;
+using System.Threading;
using log4net.Config;
using Nini.Config;
using NUnit.Framework;
@@ -38,7 +39,6 @@ using OpenSim.Framework;
using OpenSim.Region.CoreModules.Agent.TextureSender;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Tests.Common;
-using OpenSim.Tests.Common.Mock;
namespace OpenSim.Region.ClientStack.LindenUDP.Tests
{
@@ -53,6 +53,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
[TestFixtureSetUp]
public void FixtureInit()
{
+ // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
+ Util.FireAndForgetMethod = FireAndForgetMethod.None;
+
using (
Stream resource
= GetType().Assembly.GetManifestResourceStream(
@@ -72,9 +75,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
}
}
+ [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 not to worry about such things.
+ Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
+ }
+
[SetUp]
- public void SetUp()
+ public override void SetUp()
{
+ base.SetUp();
+
UUID userId = TestHelpers.ParseTail(0x3);
J2KDecoderModule j2kdm = new J2KDecoderModule();
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/MockScene.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/MockScene.cs
deleted file mode 100644
index 119a677..0000000
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/MockScene.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.Net;
-using OpenMetaverse;
-using OpenSim.Framework;
-using OpenSim.Region.Framework.Scenes;
-using GridRegion = OpenSim.Services.Interfaces.GridRegion;
-
-namespace OpenSim.Region.ClientStack.LindenUDP.Tests
-{
- ///
- /// Mock scene for unit tests
- ///
- public class MockScene : SceneBase
- {
- public int ObjectNameCallsReceived
- {
- get { return m_objectNameCallsReceived; }
- }
- protected int m_objectNameCallsReceived;
-
- public MockScene() : base(new RegionInfo(1000, 1000, null, null))
- {
- m_regStatus = RegionStatus.Up;
- }
-
- public override void Update(int frames) {}
- public override void LoadWorldMap() {}
-
- public override ISceneAgent AddNewClient(IClientAPI client, PresenceType type)
- {
- client.OnObjectName += RecordObjectNameCall;
-
- // FIXME
- return null;
- }
-
- public override void RemoveClient(UUID agentID, bool someReason) {}
-// public override void CloseAllAgents(uint circuitcode) {}
- public override bool CheckClient(UUID clientId, IPEndPoint endPoint) { return true; }
- public override void OtherRegionUp(GridRegion otherRegion) { }
-
- public override bool TryGetScenePresence(UUID uuid, out ScenePresence sp) { sp = null; return false; }
-
- ///
- /// Doesn't really matter what the call is - we're using this to test that a packet has actually been received
- ///
- protected void RecordObjectNameCall(IClientAPI remoteClient, uint localID, string message)
- {
- m_objectNameCallsReceived++;
- }
- }
-}
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs
index 5f73a94..92f1fc3 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs
@@ -30,7 +30,6 @@ using NUnit.Framework;
using OpenMetaverse;
using OpenMetaverse.Packets;
using OpenSim.Framework;
-using OpenSim.Tests.Common.Mock;
using OpenSim.Tests.Common;
namespace OpenSim.Region.ClientStack.LindenUDP.Tests
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs
deleted file mode 100644
index 27b9e5b..0000000
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * 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 System.Collections.Generic;
-using System.Net;
-using System.Net.Sockets;
-using Nini.Config;
-using OpenMetaverse.Packets;
-using OpenSim.Framework;
-
-namespace OpenSim.Region.ClientStack.LindenUDP.Tests
-{
- ///
- /// This class enables regression testing of the LLUDPServer by allowing us to intercept outgoing data.
- ///
- public class TestLLUDPServer : LLUDPServer
- {
- public List PacketsSent { get; private set; }
-
- public TestLLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager)
- : base(listenIP, ref port, proxyPortOffsetParm, allow_alternate_port, configSource, circuitManager)
- {
- PacketsSent = new List();
- }
-
- public override void SendAckImmediate(IPEndPoint remoteEndpoint, PacketAckPacket ack)
- {
- PacketsSent.Add(ack);
- }
-
- public override void SendPacket(
- LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method)
- {
- PacketsSent.Add(packet);
- }
-
- public void ClientOutgoingPacketHandler(IClientAPI client, bool resendUnacked, bool sendAcks, bool sendPing)
- {
- m_resendUnacked = resendUnacked;
- m_sendAcks = sendAcks;
- m_sendPing = sendPing;
-
- ClientOutgoingPacketHandler(client);
- }
-
-//// ///
-//// /// The chunks of data to pass to the LLUDPServer when it calls EndReceive
-//// ///
-//// protected Queue m_chunksToLoad = new Queue();
-//
-//// protected override void BeginReceive()
-//// {
-//// if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException)
-//// {
-//// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
-//// reusedEpSender = tuple.Sender;
-//// throw new SocketException();
-//// }
-//// }
-//
-//// protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
-//// {
-//// numBytes = 0;
-////
-//// //m_log.Debug("Queue size " + m_chunksToLoad.Count);
-////
-//// if (m_chunksToLoad.Count <= 0)
-//// return false;
-////
-//// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
-//// RecvBuffer = tuple.Data;
-//// numBytes = tuple.Data.Length;
-//// epSender = tuple.Sender;
-////
-//// return true;
-//// }
-//
-//// public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)
-//// {
-//// // Don't do anything just yet
-//// }
-//
-// ///
-// /// Signal that this chunk should throw an exception on Socket.BeginReceive()
-// ///
-// ///
-// public void LoadReceiveWithBeginException(EndPoint epSender)
-// {
-// ChunkSenderTuple tuple = new ChunkSenderTuple(epSender);
-// tuple.BeginReceiveException = true;
-// m_chunksToLoad.Enqueue(tuple);
-// }
-//
-// ///
-// /// Load some data to be received by the LLUDPServer on the next receive call
-// ///
-// ///
-// ///
-// public void LoadReceive(byte[] data, EndPoint epSender)
-// {
-// m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender));
-// }
-//
-// ///
-// /// Load a packet to be received by the LLUDPServer on the next receive call
-// ///
-// ///
-// public void LoadReceive(Packet packet, EndPoint epSender)
-// {
-// LoadReceive(packet.ToBytes(), epSender);
-// }
-//
-// ///
-// /// Calls the protected asynchronous result method. This fires out all data chunks currently queued for send
-// ///
-// ///
-// public void ReceiveData(IAsyncResult result)
-// {
-// // Doesn't work the same way anymore
-//// while (m_chunksToLoad.Count > 0)
-//// OnReceivedData(result);
-// }
- }
-
- ///
- /// Record the data and sender tuple
- ///
- public class ChunkSenderTuple
- {
- public byte[] Data;
- public EndPoint Sender;
- public bool BeginReceiveException;
-
- public ChunkSenderTuple(byte[] data, EndPoint sender)
- {
- Data = data;
- Sender = sender;
- }
-
- public ChunkSenderTuple(EndPoint sender)
- {
- Sender = sender;
- }
- }
-}
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 @@
+/*
+ * 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()
+ {
+ TestHelpers.InMethod();
+
+ TokenBucket tb = new TokenBucket("tb", null, 5000, 0);
+ AssertRates(tb, 5000, 0, 5000, 0);
+
+ tb.RequestedDripRate = 4000;
+ AssertRates(tb, 4000, 0, 4000, 0);
+
+ tb.RequestedDripRate = 6000;
+ AssertRates(tb, 6000, 0, 6000, 0);
+ }
+
+ [Test]
+ public void TestSetRequestDripRateWithMax()
+ {
+ TestHelpers.InMethod();
+
+ TokenBucket tb = new TokenBucket("tb", null, 5000, 10000);
+ AssertRates(tb, 5000, 0, 5000, 10000);
+
+ tb.RequestedDripRate = 4000;
+ AssertRates(tb, 4000, 0, 4000, 10000);
+
+ tb.RequestedDripRate = 6000;
+ AssertRates(tb, 6000, 0, 6000, 10000);
+
+ tb.RequestedDripRate = 12000;
+ AssertRates(tb, 10000, 0, 10000, 10000);
+ }
+
+ [Test]
+ public void TestSetRequestDripRateWithChildren()
+ {
+ TestHelpers.InMethod();
+
+ 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, 0, 3000, 0);
+ AssertRates(tbChild2, 5000, 0, 5000, 0);
+
+ // Test: Setting a parent request greater than total children requests.
+ tbParent.RequestedDripRate = 10000;
+
+ AssertRates(tbParent, 10000, 8000, 8000, 0);
+ AssertRates(tbChild1, 3000, 0, 3000, 0);
+ AssertRates(tbChild2, 5000, 0, 5000, 0);
+
+ // Test: Setting a parent request lower than total children requests.
+ tbParent.RequestedDripRate = 6000;
+
+ AssertRates(tbParent, 6000, 8000, 6000, 0);
+ AssertRates(tbChild1, 3000, 0, 6000 / 8 * 3, 0);
+ AssertRates(tbChild2, 5000, 0, 6000 / 8 * 5, 0);
+ }
+
+ private void AssertRates(
+ TokenBucket tb, double requestedDripRate, double totalDripRequest, double dripRate, double maxDripRate)
+ {
+ Assert.AreEqual((int)requestedDripRate, tb.RequestedDripRate, "Requested drip rate");
+ Assert.AreEqual((int)totalDripRequest, tb.TotalDripRequest, "Total drip request");
+ Assert.AreEqual((int)dripRate, tb.DripRate, "Drip rate");
+ Assert.AreEqual((int)maxDripRate, tb.MaxDripRate, "Max drip rate");
+ }
+
+ [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);
+ config.Set("adaptive_throttle_min_bps", 32000);
+
+ 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 275000
+ int resendBytes = 5000; // this is set low to test the minimum throttle override
+ int landBytes = 20000;
+ int windBytes = 30000;
+ int cloudBytes = 40000;
+ int taskBytes = 50000;
+ int textureBytes = 60000;
+ int assetBytes = 70000;
+ int totalBytes = resendBytes + landBytes + windBytes + cloudBytes + taskBytes + textureBytes + assetBytes;
+
+ SetThrottles(
+ udpClient, resendBytes, landBytes, windBytes, cloudBytes, taskBytes, textureBytes, assetBytes);
+
+ // Ratio of current adaptive drip rate to requested bytes, minimum rate is 32000
+ double commitRatio = 32000.0 / totalBytes;
+
+ AssertThrottles(
+ udpClient,
+ LLUDPServer.MTU, landBytes * commitRatio, windBytes * commitRatio, cloudBytes * commitRatio, taskBytes * commitRatio,
+ textureBytes * commitRatio, assetBytes * commitRatio, udpClient.FlowThrottle.AdjustedDripRate, totalBytes, 0);
+
+ // Test an increase in target throttle, ack of 20 packets adds 20 * LLUDPServer.MTU bytes
+ // to the throttle, recompute commitratio from those numbers
+ udpClient.FlowThrottle.AcknowledgePackets(20);
+ commitRatio = (32000.0 + 20.0 * LLUDPServer.MTU) / totalBytes;
+
+ AssertThrottles(
+ udpClient,
+ LLUDPServer.MTU, landBytes * commitRatio, windBytes * commitRatio, cloudBytes * commitRatio, taskBytes * commitRatio,
+ textureBytes * commitRatio, assetBytes * commitRatio, udpClient.FlowThrottle.AdjustedDripRate, totalBytes, 0);
+
+ // Test a decrease in target throttle, adaptive throttle should cut the rate by 50% with a floor
+ // set by the minimum adaptive rate
+ udpClient.FlowThrottle.ExpirePackets(1);
+ commitRatio = (32000.0 + (20.0 * LLUDPServer.MTU)/Math.Pow(2,1)) / totalBytes;
+
+ AssertThrottles(
+ udpClient,
+ LLUDPServer.MTU, landBytes * commitRatio, windBytes * commitRatio, cloudBytes * commitRatio, taskBytes * commitRatio,
+ textureBytes * commitRatio, assetBytes * commitRatio, udpClient.FlowThrottle.AdjustedDripRate, totalBytes, 0);
+ }
+
+ ///
+ /// Test throttle setttings where max client throttle has been limited server side.
+ ///
+ [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);
+ }
+
+ ///
+ /// Test throttle setttings where max client throttle has been limited server side.
+ ///
+ [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, "Resend");
+ Assert.AreEqual((int)landBytes, ci.landThrottle, "Land");
+ Assert.AreEqual((int)windBytes, ci.windThrottle, "Wind");
+ Assert.AreEqual((int)cloudBytes, ci.cloudThrottle, "Cloud");
+ Assert.AreEqual((int)taskBytes, ci.taskThrottle, "Task");
+ Assert.AreEqual((int)textureBytes, ci.textureThrottle, "Texture");
+ Assert.AreEqual((int)assetBytes, ci.assetThrottle, "Asset");
+ Assert.AreEqual((int)totalBytes, ci.totalThrottle, "Total");
+ Assert.AreEqual((int)targetBytes, ci.targetThrottle, "Target");
+ Assert.AreEqual((int)maxBytes, ci.maxThrottle, "Max");
+ }
+
+ 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);
+ }
+ }
+}
\ No newline at end of file
--
cgit v1.1