aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/Tests')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs299
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/MockScene.cs72
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs106
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLPacketServer.cs72
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs153
5 files changed, 702 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..daab84f
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
@@ -0,0 +1,299 @@
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
28using System.Net;
29using log4net.Config;
30using Nini.Config;
31using NUnit.Framework;
32using NUnit.Framework.SyntaxHelpers;
33using OpenMetaverse;
34using OpenMetaverse.Packets;
35using OpenSim.Framework;
36using OpenSim.Tests.Common;
37using OpenSim.Tests.Common.Mock;
38
39namespace OpenSim.Region.ClientStack.LindenUDP.Tests
40{
41 /// <summary>
42 /// This will contain basic tests for the LindenUDP client stack
43 /// </summary>
44 [TestFixture]
45 public class BasicCircuitTests
46 {
47 [SetUp]
48 public void Init()
49 {
50 try
51 {
52 XmlConfigurator.Configure();
53 }
54 catch
55 {
56 // I don't care, just leave log4net off
57 }
58 }
59
60 /// <summary>
61 /// Add a client for testing
62 /// </summary>
63 /// <param name="scene"></param>
64 /// <param name="testLLUDPServer"></param>
65 /// <param name="testPacketServer"></param>
66 /// <param name="acm">Agent circuit manager used in setting up the stack</param>
67 protected void SetupStack(
68 IScene scene, out TestLLUDPServer testLLUDPServer, out TestLLPacketServer testPacketServer,
69 out AgentCircuitManager acm)
70 {
71 IConfigSource configSource = new IniConfigSource();
72 ClientStackUserSettings userSettings = new ClientStackUserSettings();
73 testLLUDPServer = new TestLLUDPServer();
74 acm = new AgentCircuitManager();
75
76 uint port = 666;
77 testLLUDPServer.Initialise(null, ref port, 0, false, configSource, acm);
78 testPacketServer = new TestLLPacketServer(testLLUDPServer, userSettings);
79 testLLUDPServer.LocalScene = scene;
80 }
81
82 /// <summary>
83 /// Set up a client for tests which aren't concerned with this process itself and where only one client is being
84 /// tested
85 /// </summary>
86 /// <param name="circuitCode"></param>
87 /// <param name="epSender"></param>
88 /// <param name="testLLUDPServer"></param>
89 /// <param name="acm"></param>
90 protected void AddClient(
91 uint circuitCode, EndPoint epSender, TestLLUDPServer testLLUDPServer, AgentCircuitManager acm)
92 {
93 UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001");
94 UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002");
95
96 AddClient(circuitCode, epSender, myAgentUuid, mySessionUuid, testLLUDPServer, acm);
97 }
98
99 /// <summary>
100 /// Set up a client for tests which aren't concerned with this process itself
101 /// </summary>
102 /// <param name="circuitCode"></param>
103 /// <param name="epSender"></param>
104 /// <param name="agentId"></param>
105 /// <param name="sessionId"></param>
106 /// <param name="testLLUDPServer"></param>
107 /// <param name="acm"></param>
108 protected void AddClient(
109 uint circuitCode, EndPoint epSender, UUID agentId, UUID sessionId,
110 TestLLUDPServer testLLUDPServer, AgentCircuitManager acm)
111 {
112 AgentCircuitData acd = new AgentCircuitData();
113 acd.AgentID = agentId;
114 acd.SessionID = sessionId;
115
116 UseCircuitCodePacket uccp = new UseCircuitCodePacket();
117
118 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
119 = new UseCircuitCodePacket.CircuitCodeBlock();
120 uccpCcBlock.Code = circuitCode;
121 uccpCcBlock.ID = agentId;
122 uccpCcBlock.SessionID = sessionId;
123 uccp.CircuitCode = uccpCcBlock;
124
125 acm.AddNewCircuit(circuitCode, acd);
126
127 testLLUDPServer.LoadReceive(uccp, epSender);
128 testLLUDPServer.ReceiveData(null);
129 }
130
131 /// <summary>
132 /// Build an object name packet for test purposes
133 /// </summary>
134 /// <param name="objectLocalId"></param>
135 /// <param name="objectName"></param>
136 protected ObjectNamePacket BuildTestObjectNamePacket(uint objectLocalId, string objectName)
137 {
138 ObjectNamePacket onp = new ObjectNamePacket();
139 ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock();
140 odb.LocalID = objectLocalId;
141 odb.Name = Utils.StringToBytes(objectName);
142 onp.ObjectData = new ObjectNamePacket.ObjectDataBlock[] { odb };
143 onp.Header.Zerocoded = false;
144
145 return onp;
146 }
147
148 /// <summary>
149 /// Test adding a client to the stack
150 /// </summary>
151 [Test, LongRunning]
152 public void TestAddClient()
153 {
154 TestHelper.InMethod();
155
156 uint myCircuitCode = 123456;
157 UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001");
158 UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002");
159
160 TestLLUDPServer testLLUDPServer;
161 TestLLPacketServer testLLPacketServer;
162 AgentCircuitManager acm;
163 SetupStack(new MockScene(), out testLLUDPServer, out testLLPacketServer, out acm);
164
165 AgentCircuitData acd = new AgentCircuitData();
166 acd.AgentID = myAgentUuid;
167 acd.SessionID = mySessionUuid;
168
169 UseCircuitCodePacket uccp = new UseCircuitCodePacket();
170
171 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
172 = new UseCircuitCodePacket.CircuitCodeBlock();
173 uccpCcBlock.Code = myCircuitCode;
174 uccpCcBlock.ID = myAgentUuid;
175 uccpCcBlock.SessionID = mySessionUuid;
176 uccp.CircuitCode = uccpCcBlock;
177
178 EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
179
180 testLLUDPServer.LoadReceive(uccp, testEp);
181 testLLUDPServer.ReceiveData(null);
182
183 // Circuit shouildn't exist since the circuit manager doesn't know about this circuit for authentication yet
184 Assert.IsFalse(testLLUDPServer.HasCircuit(myCircuitCode));
185
186 acm.AddNewCircuit(myCircuitCode, acd);
187
188 testLLUDPServer.LoadReceive(uccp, testEp);
189 testLLUDPServer.ReceiveData(null);
190
191 // Should succeed now
192 Assert.IsTrue(testLLUDPServer.HasCircuit(myCircuitCode));
193 Assert.IsFalse(testLLUDPServer.HasCircuit(101));
194 }
195
196 /// <summary>
197 /// Test removing a client from the stack
198 /// </summary>
199 [Test]
200 public void TestRemoveClient()
201 {
202 TestHelper.InMethod();
203
204 uint myCircuitCode = 123457;
205
206 TestLLUDPServer testLLUDPServer;
207 TestLLPacketServer testLLPacketServer;
208 AgentCircuitManager acm;
209 SetupStack(new MockScene(), out testLLUDPServer, out testLLPacketServer, out acm);
210 AddClient(myCircuitCode, new IPEndPoint(IPAddress.Loopback, 1000), testLLUDPServer, acm);
211
212 testLLUDPServer.RemoveClientCircuit(myCircuitCode);
213 Assert.IsFalse(testLLUDPServer.HasCircuit(myCircuitCode));
214
215 // Check that removing a non-existant circuit doesn't have any bad effects
216 testLLUDPServer.RemoveClientCircuit(101);
217 Assert.IsFalse(testLLUDPServer.HasCircuit(101));
218 }
219
220 /// <summary>
221 /// Make sure that the client stack reacts okay to malformed packets
222 /// </summary>
223 [Test]
224 public void TestMalformedPacketSend()
225 {
226 TestHelper.InMethod();
227
228 uint myCircuitCode = 123458;
229 EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 1001);
230 MockScene scene = new MockScene();
231
232 TestLLUDPServer testLLUDPServer;
233 TestLLPacketServer testLLPacketServer;
234 AgentCircuitManager acm;
235 SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm);
236 AddClient(myCircuitCode, testEp, testLLUDPServer, acm);
237
238 byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04 };
239
240 // Send two garbled 'packets' in succession
241 testLLUDPServer.LoadReceive(data, testEp);
242 testLLUDPServer.LoadReceive(data, testEp);
243 testLLUDPServer.ReceiveData(null);
244
245 // Check that we are still here
246 Assert.IsTrue(testLLUDPServer.HasCircuit(myCircuitCode));
247 Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(0));
248
249 // Check that sending a valid packet to same circuit still succeeds
250 Assert.That(scene.ObjectNameCallsReceived, Is.EqualTo(0));
251
252 testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "helloooo"), testEp);
253 testLLUDPServer.ReceiveData(null);
254
255 Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(1));
256 Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(1));
257 }
258
259 /// <summary>
260 /// Test that the stack continues to work even if some client has caused a
261 /// SocketException on Socket.BeginReceive()
262 /// </summary>
263 [Test]
264 public void TestExceptionOnBeginReceive()
265 {
266 TestHelper.InMethod();
267
268 MockScene scene = new MockScene();
269
270 uint circuitCodeA = 130000;
271 EndPoint epA = new IPEndPoint(IPAddress.Loopback, 1300);
272 UUID agentIdA = UUID.Parse("00000000-0000-0000-0000-000000001300");
273 UUID sessionIdA = UUID.Parse("00000000-0000-0000-0000-000000002300");
274
275 uint circuitCodeB = 130001;
276 EndPoint epB = new IPEndPoint(IPAddress.Loopback, 1301);
277 UUID agentIdB = UUID.Parse("00000000-0000-0000-0000-000000001301");
278 UUID sessionIdB = UUID.Parse("00000000-0000-0000-0000-000000002301");
279
280 TestLLUDPServer testLLUDPServer;
281 TestLLPacketServer testLLPacketServer;
282 AgentCircuitManager acm;
283 SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm);
284 AddClient(circuitCodeA, epA, agentIdA, sessionIdA, testLLUDPServer, acm);
285 AddClient(circuitCodeB, epB, agentIdB, sessionIdB, testLLUDPServer, acm);
286
287 testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "packet1"), epA);
288 testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "packet2"), epB);
289 testLLUDPServer.LoadReceiveWithBeginException(epA);
290 testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(2, "packet3"), epB);
291 testLLUDPServer.ReceiveData(null);
292
293 Assert.IsFalse(testLLUDPServer.HasCircuit(circuitCodeA));
294
295 Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(3));
296 Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(3));
297 }
298 }
299}
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/MockScene.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/MockScene.cs
new file mode 100644
index 0000000..34c21aa
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/MockScene.cs
@@ -0,0 +1,72 @@
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
28using OpenMetaverse;
29using OpenSim.Framework;
30using OpenSim.Region.Framework.Scenes;
31using GridRegion = OpenSim.Services.Interfaces.GridRegion;
32
33namespace OpenSim.Region.ClientStack.LindenUDP.Tests
34{
35 /// <summary>
36 /// Mock scene for unit tests
37 /// </summary>
38 public class MockScene : SceneBase
39 {
40 public int ObjectNameCallsReceived
41 {
42 get { return m_objectNameCallsReceived; }
43 }
44 protected int m_objectNameCallsReceived;
45
46 public MockScene()
47 {
48 m_regInfo = new RegionInfo(1000, 1000, null, null);
49 m_regStatus = RegionStatus.Up;
50 }
51
52 public override void Update() {}
53 public override void LoadWorldMap() {}
54
55 public override void AddNewClient(IClientAPI client)
56 {
57 client.OnObjectName += RecordObjectNameCall;
58 }
59
60 public override void RemoveClient(UUID agentID) {}
61 public override void CloseAllAgents(uint circuitcode) {}
62 public override void OtherRegionUp(GridRegion otherRegion) { }
63
64 /// <summary>
65 /// Doesn't really matter what the call is - we're using this to test that a packet has actually been received
66 /// </summary>
67 protected void RecordObjectNameCall(IClientAPI remoteClient, uint localID, string message)
68 {
69 m_objectNameCallsReceived++;
70 }
71 }
72}
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..7d0757f
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/PacketHandlerTests.cs
@@ -0,0 +1,106 @@
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
28using Nini.Config;
29using NUnit.Framework;
30using NUnit.Framework.SyntaxHelpers;
31using OpenMetaverse;
32using OpenMetaverse.Packets;
33using OpenSim.Framework;
34using OpenSim.Tests.Common.Mock;
35using OpenSim.Tests.Common;
36
37namespace OpenSim.Region.ClientStack.LindenUDP.Tests
38{
39 /// <summary>
40 /// Tests for the LL packet handler
41 /// </summary>
42 [TestFixture]
43 public class PacketHandlerTests
44 {
45 [Test]
46 /// <summary>
47 /// More a placeholder, really
48 /// </summary>
49 public void InPacketTest()
50 {
51 TestHelper.InMethod();
52
53 AgentCircuitData agent = new AgentCircuitData();
54 agent.AgentID = UUID.Random();
55 agent.firstname = "testfirstname";
56 agent.lastname = "testlastname";
57 agent.SessionID = UUID.Zero;
58 agent.SecureSessionID = UUID.Zero;
59 agent.circuitcode = 123;
60 agent.BaseFolder = UUID.Zero;
61 agent.InventoryFolder = UUID.Zero;
62 agent.startpos = Vector3.Zero;
63 agent.CapsPath = "http://wibble.com";
64
65 TestLLUDPServer testLLUDPServer;
66 TestLLPacketServer testLLPacketServer;
67 AgentCircuitManager acm;
68 IScene scene = new MockScene();
69 SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm);
70
71 TestClient testClient = new TestClient(agent, scene);
72
73 LLPacketHandler packetHandler
74 = new LLPacketHandler(testClient, testLLPacketServer, new ClientStackUserSettings());
75
76 packetHandler.InPacket(new AgentAnimationPacket());
77 LLQueItem receivedPacket = packetHandler.PacketQueue.Dequeue();
78
79 Assert.That(receivedPacket, Is.Not.Null);
80 Assert.That(receivedPacket.Incoming, Is.True);
81 Assert.That(receivedPacket.Packet, Is.TypeOf(typeof(AgentAnimationPacket)));
82 }
83
84 /// <summary>
85 /// Add a client for testing
86 /// </summary>
87 /// <param name="scene"></param>
88 /// <param name="testLLUDPServer"></param>
89 /// <param name="testPacketServer"></param>
90 /// <param name="acm">Agent circuit manager used in setting up the stack</param>
91 protected void SetupStack(
92 IScene scene, out TestLLUDPServer testLLUDPServer, out TestLLPacketServer testPacketServer,
93 out AgentCircuitManager acm)
94 {
95 IConfigSource configSource = new IniConfigSource();
96 ClientStackUserSettings userSettings = new ClientStackUserSettings();
97 testLLUDPServer = new TestLLUDPServer();
98 acm = new AgentCircuitManager();
99
100 uint port = 666;
101 testLLUDPServer.Initialise(null, ref port, 0, false, configSource, acm);
102 testPacketServer = new TestLLPacketServer(testLLUDPServer, userSettings);
103 testLLUDPServer.LocalScene = scene;
104 }
105 }
106}
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLPacketServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLPacketServer.cs
new file mode 100644
index 0000000..e995d65
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLPacketServer.cs
@@ -0,0 +1,72 @@
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
28using System.Collections.Generic;
29using OpenMetaverse.Packets;
30
31namespace OpenSim.Region.ClientStack.LindenUDP.Tests
32{
33 public class TestLLPacketServer : LLPacketServer
34 {
35 /// <summary>
36 /// Record counts of packets received
37 /// </summary>
38 protected Dictionary<PacketType, int> m_packetsReceived = new Dictionary<PacketType, int>();
39
40 public TestLLPacketServer(LLUDPServer networkHandler, ClientStackUserSettings userSettings)
41 : base(networkHandler, userSettings)
42 {}
43
44 public override void InPacket(uint circuitCode, Packet packet)
45 {
46 base.InPacket(circuitCode, packet);
47
48 if (m_packetsReceived.ContainsKey(packet.Type))
49 m_packetsReceived[packet.Type]++;
50 else
51 m_packetsReceived[packet.Type] = 1;
52 }
53
54 public int GetTotalPacketsReceived()
55 {
56 int totalCount = 0;
57
58 foreach (int count in m_packetsReceived.Values)
59 totalCount += count;
60
61 return totalCount;
62 }
63
64 public int GetPacketsReceivedFor(PacketType packetType)
65 {
66 if (m_packetsReceived.ContainsKey(packetType))
67 return m_packetsReceived[packetType];
68 else
69 return 0;
70 }
71 }
72}
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs
new file mode 100644
index 0000000..f98586d
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs
@@ -0,0 +1,153 @@
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
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Net.Sockets;
32using OpenMetaverse.Packets;
33
34namespace OpenSim.Region.ClientStack.LindenUDP.Tests
35{
36 /// <summary>
37 /// This class enables synchronous testing of the LLUDPServer by allowing us to load our own data into the end
38 /// receive event
39 /// </summary>
40 public class TestLLUDPServer : LLUDPServer
41 {
42 /// <summary>
43 /// The chunks of data to pass to the LLUDPServer when it calls EndReceive
44 /// </summary>
45 protected Queue<ChunkSenderTuple> m_chunksToLoad = new Queue<ChunkSenderTuple>();
46
47 protected override void BeginReceive()
48 {
49 if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException)
50 {
51 ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
52 reusedEpSender = tuple.Sender;
53 throw new SocketException();
54 }
55 }
56
57 protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
58 {
59 numBytes = 0;
60
61 //m_log.Debug("Queue size " + m_chunksToLoad.Count);
62
63 if (m_chunksToLoad.Count <= 0)
64 return false;
65
66 ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
67 RecvBuffer = tuple.Data;
68 numBytes = tuple.Data.Length;
69 epSender = tuple.Sender;
70
71 return true;
72 }
73
74 public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)
75 {
76 // Don't do anything just yet
77 }
78
79 /// <summary>
80 /// Signal that this chunk should throw an exception on Socket.BeginReceive()
81 /// </summary>
82 /// <param name="epSender"></param>
83 public void LoadReceiveWithBeginException(EndPoint epSender)
84 {
85 ChunkSenderTuple tuple = new ChunkSenderTuple(epSender);
86 tuple.BeginReceiveException = true;
87 m_chunksToLoad.Enqueue(tuple);
88 }
89
90 /// <summary>
91 /// Load some data to be received by the LLUDPServer on the next receive call
92 /// </summary>
93 /// <param name="data"></param>
94 /// <param name="epSender"></param>
95 public void LoadReceive(byte[] data, EndPoint epSender)
96 {
97 m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender));
98 }
99
100 /// <summary>
101 /// Load a packet to be received by the LLUDPServer on the next receive call
102 /// </summary>
103 /// <param name="packet"></param>
104 public void LoadReceive(Packet packet, EndPoint epSender)
105 {
106 LoadReceive(packet.ToBytes(), epSender);
107 }
108
109 /// <summary>
110 /// Calls the protected asynchronous result method. This fires out all data chunks currently queued for send
111 /// </summary>
112 /// <param name="result"></param>
113 public void ReceiveData(IAsyncResult result)
114 {
115 while (m_chunksToLoad.Count > 0)
116 OnReceivedData(result);
117 }
118
119 /// <summary>
120 /// Has a circuit with the given code been established?
121 /// </summary>
122 /// <param name="circuitCode"></param>
123 /// <returns></returns>
124 public bool HasCircuit(uint circuitCode)
125 {
126 lock (clientCircuits_reverse)
127 {
128 return clientCircuits_reverse.ContainsKey(circuitCode);
129 }
130 }
131 }
132
133 /// <summary>
134 /// Record the data and sender tuple
135 /// </summary>
136 public class ChunkSenderTuple
137 {
138 public byte[] Data;
139 public EndPoint Sender;
140 public bool BeginReceiveException;
141
142 public ChunkSenderTuple(byte[] data, EndPoint sender)
143 {
144 Data = data;
145 Sender = sender;
146 }
147
148 public ChunkSenderTuple(EndPoint sender)
149 {
150 Sender = sender;
151 }
152 }
153}