clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 | using OpenSim.Tests.Common.Mock; |
||
40 | |||
41 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests |
||
42 | { |
||
43 | /// <summary> |
||
44 | /// This will contain basic tests for the LindenUDP client stack |
||
45 | /// </summary> |
||
46 | [TestFixture] |
||
47 | public class BasicCircuitTests : OpenSimTestCase |
||
48 | { |
||
49 | private Scene m_scene; |
||
50 | private TestLLUDPServer m_udpServer; |
||
51 | |||
52 | [TestFixtureSetUp] |
||
53 | public void FixtureInit() |
||
54 | { |
||
55 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. |
||
56 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; |
||
57 | } |
||
58 | |||
59 | [TestFixtureTearDown] |
||
60 | public void TearDown() |
||
61 | { |
||
62 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple |
||
63 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression |
||
64 | // tests really shouldn't). |
||
65 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; |
||
66 | } |
||
67 | |||
68 | [SetUp] |
||
69 | public override void SetUp() |
||
70 | { |
||
71 | base.SetUp(); |
||
72 | m_scene = new SceneHelpers().SetupScene(); |
||
73 | StatsManager.SimExtraStats = new SimExtraStatsCollector(); |
||
74 | } |
||
75 | |||
76 | /// <summary> |
||
77 | /// Build an object name packet for test purposes |
||
78 | /// </summary> |
||
79 | /// <param name="objectLocalId"></param> |
||
80 | /// <param name="objectName"></param> |
||
81 | private ObjectNamePacket BuildTestObjectNamePacket(uint objectLocalId, string objectName) |
||
82 | { |
||
83 | ObjectNamePacket onp = new ObjectNamePacket(); |
||
84 | ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock(); |
||
85 | odb.LocalID = objectLocalId; |
||
86 | odb.Name = Utils.StringToBytes(objectName); |
||
87 | onp.ObjectData = new ObjectNamePacket.ObjectDataBlock[] { odb }; |
||
88 | onp.Header.Zerocoded = false; |
||
89 | |||
90 | return onp; |
||
91 | } |
||
92 | |||
93 | private void AddUdpServer() |
||
94 | { |
||
95 | AddUdpServer(new IniConfigSource()); |
||
96 | } |
||
97 | |||
98 | private void AddUdpServer(IniConfigSource configSource) |
||
99 | { |
||
100 | uint port = 0; |
||
101 | AgentCircuitManager acm = m_scene.AuthenticateHandler; |
||
102 | |||
103 | m_udpServer = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, configSource, acm); |
||
104 | m_udpServer.AddScene(m_scene); |
||
105 | } |
||
106 | |||
107 | /// <summary> |
||
108 | /// Used by tests that aren't testing this stage. |
||
109 | /// </summary> |
||
110 | private ScenePresence AddClient() |
||
111 | { |
||
112 | UUID myAgentUuid = TestHelpers.ParseTail(0x1); |
||
113 | UUID mySessionUuid = TestHelpers.ParseTail(0x2); |
||
114 | uint myCircuitCode = 123456; |
||
115 | IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999); |
||
116 | |||
117 | UseCircuitCodePacket uccp = new UseCircuitCodePacket(); |
||
118 | |||
119 | UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock |
||
120 | = new UseCircuitCodePacket.CircuitCodeBlock(); |
||
121 | uccpCcBlock.Code = myCircuitCode; |
||
122 | uccpCcBlock.ID = myAgentUuid; |
||
123 | uccpCcBlock.SessionID = mySessionUuid; |
||
124 | uccp.CircuitCode = uccpCcBlock; |
||
125 | |||
126 | byte[] uccpBytes = uccp.ToBytes(); |
||
127 | UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length); |
||
128 | upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor. |
||
129 | Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length); |
||
130 | |||
131 | AgentCircuitData acd = new AgentCircuitData(); |
||
132 | acd.AgentID = myAgentUuid; |
||
133 | acd.SessionID = mySessionUuid; |
||
134 | |||
135 | m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd); |
||
136 | |||
137 | m_udpServer.PacketReceived(upb); |
||
138 | |||
139 | return m_scene.GetScenePresence(myAgentUuid); |
||
140 | } |
||
141 | |||
142 | /// <summary> |
||
143 | /// Test adding a client to the stack |
||
144 | /// </summary> |
||
145 | [Test] |
||
146 | public void TestAddClient() |
||
147 | { |
||
148 | TestHelpers.InMethod(); |
||
149 | // TestHelpers.EnableLogging(); |
||
150 | |||
151 | AddUdpServer(); |
||
152 | |||
153 | UUID myAgentUuid = TestHelpers.ParseTail(0x1); |
||
154 | UUID mySessionUuid = TestHelpers.ParseTail(0x2); |
||
155 | uint myCircuitCode = 123456; |
||
156 | IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999); |
||
157 | |||
158 | UseCircuitCodePacket uccp = new UseCircuitCodePacket(); |
||
159 | |||
160 | UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock |
||
161 | = new UseCircuitCodePacket.CircuitCodeBlock(); |
||
162 | uccpCcBlock.Code = myCircuitCode; |
||
163 | uccpCcBlock.ID = myAgentUuid; |
||
164 | uccpCcBlock.SessionID = mySessionUuid; |
||
165 | uccp.CircuitCode = uccpCcBlock; |
||
166 | |||
167 | byte[] uccpBytes = uccp.ToBytes(); |
||
168 | UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length); |
||
169 | upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor. |
||
170 | Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length); |
||
171 | |||
172 | m_udpServer.PacketReceived(upb); |
||
173 | |||
174 | // Presence shouldn't exist since the circuit manager doesn't know about this circuit for authentication yet |
||
175 | Assert.That(m_scene.GetScenePresence(myAgentUuid), Is.Null); |
||
176 | |||
177 | AgentCircuitData acd = new AgentCircuitData(); |
||
178 | acd.AgentID = myAgentUuid; |
||
179 | acd.SessionID = mySessionUuid; |
||
180 | |||
181 | m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd); |
||
182 | |||
183 | m_udpServer.PacketReceived(upb); |
||
184 | |||
185 | // Should succeed now |
||
186 | ScenePresence sp = m_scene.GetScenePresence(myAgentUuid); |
||
187 | Assert.That(sp.UUID, Is.EqualTo(myAgentUuid)); |
||
188 | |||
189 | Assert.That(m_udpServer.PacketsSent.Count, Is.EqualTo(1)); |
||
190 | |||
191 | Packet packet = m_udpServer.PacketsSent[0]; |
||
192 | Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket))); |
||
193 | |||
194 | PacketAckPacket ackPacket = packet as PacketAckPacket; |
||
195 | Assert.That(ackPacket.Packets.Length, Is.EqualTo(1)); |
||
196 | Assert.That(ackPacket.Packets[0].ID, Is.EqualTo(0)); |
||
197 | } |
||
198 | |||
199 | [Test] |
||
200 | public void TestLogoutClientDueToAck() |
||
201 | { |
||
202 | TestHelpers.InMethod(); |
||
203 | TestHelpers.EnableLogging(); |
||
204 | |||
205 | IniConfigSource ics = new IniConfigSource(); |
||
206 | IConfig config = ics.AddConfig("ClientStack.LindenUDP"); |
||
207 | config.Set("AckTimeout", -1); |
||
208 | AddUdpServer(ics); |
||
209 | |||
210 | ScenePresence sp = AddClient(); |
||
211 | m_udpServer.ClientOutgoingPacketHandler(sp.ControllingClient, true, false, false); |
||
212 | |||
213 | ScenePresence spAfterAckTimeout = m_scene.GetScenePresence(sp.UUID); |
||
214 | Assert.That(spAfterAckTimeout, Is.Null); |
||
215 | } |
||
216 | |||
217 | // /// <summary> |
||
218 | // /// Test removing a client from the stack |
||
219 | // /// </summary> |
||
220 | // [Test] |
||
221 | // public void TestRemoveClient() |
||
222 | // { |
||
223 | // TestHelper.InMethod(); |
||
224 | // |
||
225 | // uint myCircuitCode = 123457; |
||
226 | // |
||
227 | // TestLLUDPServer testLLUDPServer; |
||
228 | // TestLLPacketServer testLLPacketServer; |
||
229 | // AgentCircuitManager acm; |
||
230 | // SetupStack(new MockScene(), out testLLUDPServer, out testLLPacketServer, out acm); |
||
231 | // AddClient(myCircuitCode, new IPEndPoint(IPAddress.Loopback, 1000), testLLUDPServer, acm); |
||
232 | // |
||
233 | // testLLUDPServer.RemoveClientCircuit(myCircuitCode); |
||
234 | // Assert.IsFalse(testLLUDPServer.HasCircuit(myCircuitCode)); |
||
235 | // |
||
236 | // // Check that removing a non-existent circuit doesn't have any bad effects |
||
237 | // testLLUDPServer.RemoveClientCircuit(101); |
||
238 | // Assert.IsFalse(testLLUDPServer.HasCircuit(101)); |
||
239 | // } |
||
240 | // |
||
241 | // /// <summary> |
||
242 | // /// Make sure that the client stack reacts okay to malformed packets |
||
243 | // /// </summary> |
||
244 | // [Test] |
||
245 | // public void TestMalformedPacketSend() |
||
246 | // { |
||
247 | // TestHelper.InMethod(); |
||
248 | // |
||
249 | // uint myCircuitCode = 123458; |
||
250 | // EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 1001); |
||
251 | // MockScene scene = new MockScene(); |
||
252 | // |
||
253 | // TestLLUDPServer testLLUDPServer; |
||
254 | // TestLLPacketServer testLLPacketServer; |
||
255 | // AgentCircuitManager acm; |
||
256 | // SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm); |
||
257 | // AddClient(myCircuitCode, testEp, testLLUDPServer, acm); |
||
258 | // |
||
259 | // byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04 }; |
||
260 | // |
||
261 | // // Send two garbled 'packets' in succession |
||
262 | // testLLUDPServer.LoadReceive(data, testEp); |
||
263 | // testLLUDPServer.LoadReceive(data, testEp); |
||
264 | // testLLUDPServer.ReceiveData(null); |
||
265 | // |
||
266 | // // Check that we are still here |
||
267 | // Assert.IsTrue(testLLUDPServer.HasCircuit(myCircuitCode)); |
||
268 | // Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(0)); |
||
269 | // |
||
270 | // // Check that sending a valid packet to same circuit still succeeds |
||
271 | // Assert.That(scene.ObjectNameCallsReceived, Is.EqualTo(0)); |
||
272 | // |
||
273 | // testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "helloooo"), testEp); |
||
274 | // testLLUDPServer.ReceiveData(null); |
||
275 | // |
||
276 | // Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(1)); |
||
277 | // Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(1)); |
||
278 | // } |
||
279 | // |
||
280 | // /// <summary> |
||
281 | // /// Test that the stack continues to work even if some client has caused a |
||
282 | // /// SocketException on Socket.BeginReceive() |
||
283 | // /// </summary> |
||
284 | // [Test] |
||
285 | // public void TestExceptionOnBeginReceive() |
||
286 | // { |
||
287 | // TestHelper.InMethod(); |
||
288 | // |
||
289 | // MockScene scene = new MockScene(); |
||
290 | // |
||
291 | // uint circuitCodeA = 130000; |
||
292 | // EndPoint epA = new IPEndPoint(IPAddress.Loopback, 1300); |
||
293 | // UUID agentIdA = UUID.Parse("00000000-0000-0000-0000-000000001300"); |
||
294 | // UUID sessionIdA = UUID.Parse("00000000-0000-0000-0000-000000002300"); |
||
295 | // |
||
296 | // uint circuitCodeB = 130001; |
||
297 | // EndPoint epB = new IPEndPoint(IPAddress.Loopback, 1301); |
||
298 | // UUID agentIdB = UUID.Parse("00000000-0000-0000-0000-000000001301"); |
||
299 | // UUID sessionIdB = UUID.Parse("00000000-0000-0000-0000-000000002301"); |
||
300 | // |
||
301 | // TestLLUDPServer testLLUDPServer; |
||
302 | // TestLLPacketServer testLLPacketServer; |
||
303 | // AgentCircuitManager acm; |
||
304 | // SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm); |
||
305 | // AddClient(circuitCodeA, epA, agentIdA, sessionIdA, testLLUDPServer, acm); |
||
306 | // AddClient(circuitCodeB, epB, agentIdB, sessionIdB, testLLUDPServer, acm); |
||
307 | // |
||
308 | // testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "packet1"), epA); |
||
309 | // testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "packet2"), epB); |
||
310 | // testLLUDPServer.LoadReceiveWithBeginException(epA); |
||
311 | // testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(2, "packet3"), epB); |
||
312 | // testLLUDPServer.ReceiveData(null); |
||
313 | // |
||
314 | // Assert.IsFalse(testLLUDPServer.HasCircuit(circuitCodeA)); |
||
315 | // |
||
316 | // Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(3)); |
||
317 | // Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(3)); |
||
318 | // } |
||
319 | } |
||
320 | } |