aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-10-08 20:17:51 +0100
committerJustin Clark-Casey (justincc)2014-11-25 23:18:40 +0000
commit52370ac94de4f449645eb0471fab4cc515fccbe2 (patch)
tree1b920cad4f0416420a8fec9f804b1272bf92166e /OpenSim/Tests
parentFix recent regression in "debug lludp throttles get" command that stopped it ... (diff)
downloadopensim-SC_OLD-52370ac94de4f449645eb0471fab4cc515fccbe2.zip
opensim-SC_OLD-52370ac94de4f449645eb0471fab4cc515fccbe2.tar.gz
opensim-SC_OLD-52370ac94de4f449645eb0471fab4cc515fccbe2.tar.bz2
opensim-SC_OLD-52370ac94de4f449645eb0471fab4cc515fccbe2.tar.xz
refactor: Move test clientstack setup code out of BasicCircuitTests into OpenSim.Tests.Common.ClientStackHelpers
Diffstat (limited to 'OpenSim/Tests')
-rw-r--r--OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs95
-rw-r--r--OpenSim/Tests/Common/Mock/TestLLUDPServer.cs171
2 files changed, 266 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs b/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs
new file mode 100644
index 0000000..33cd8a2
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs
@@ -0,0 +1,95 @@
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.Net;
30using Nini.Config;
31using OpenMetaverse;
32using OpenMetaverse.Packets;
33using OpenSim.Framework;
34using OpenSim.Region.ClientStack.LindenUDP;
35using OpenSim.Region.Framework.Scenes;
36
37namespace OpenSim.Tests.Common
38{
39 /// <summary>
40 /// This class adds full UDP client classes and associated scene presence to scene.
41 /// </summary>
42 /// <remarks>
43 /// This is used for testing client stack code. For testing other code, use SceneHelper methods instead since
44 /// they operate without the burden of setting up UDP structures which should be unnecessary for testing scene
45 /// code.
46 /// </remarks>
47 public static class ClientStackHelpers
48 {
49 public static ScenePresence AddChildClient(
50 Scene scene, LLUDPServer udpServer, UUID agentId, UUID sessionId, uint circuitCode)
51 {
52 IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
53
54 UseCircuitCodePacket uccp = new UseCircuitCodePacket();
55
56 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
57 = new UseCircuitCodePacket.CircuitCodeBlock();
58 uccpCcBlock.Code = circuitCode;
59 uccpCcBlock.ID = agentId;
60 uccpCcBlock.SessionID = sessionId;
61 uccp.CircuitCode = uccpCcBlock;
62
63 byte[] uccpBytes = uccp.ToBytes();
64 UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length);
65 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
66 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
67
68 AgentCircuitData acd = new AgentCircuitData();
69 acd.AgentID = agentId;
70 acd.SessionID = sessionId;
71
72 scene.AuthenticateHandler.AddNewCircuit(circuitCode, acd);
73
74 udpServer.PacketReceived(upb);
75
76 return scene.GetScenePresence(agentId);
77 }
78
79 public static TestLLUDPServer AddUdpServer(Scene scene)
80 {
81 return AddUdpServer(scene, new IniConfigSource());
82 }
83
84 public static TestLLUDPServer AddUdpServer(Scene scene, IniConfigSource configSource)
85 {
86 uint port = 0;
87 AgentCircuitManager acm = scene.AuthenticateHandler;
88
89 TestLLUDPServer udpServer = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, configSource, acm);
90 udpServer.AddScene(scene);
91
92 return udpServer;
93 }
94 }
95} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Mock/TestLLUDPServer.cs b/OpenSim/Tests/Common/Mock/TestLLUDPServer.cs
new file mode 100644
index 0000000..26887c9
--- /dev/null
+++ b/OpenSim/Tests/Common/Mock/TestLLUDPServer.cs
@@ -0,0 +1,171 @@
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 Nini.Config;
33using OpenMetaverse.Packets;
34using OpenSim.Framework;
35using OpenSim.Region.ClientStack.LindenUDP;
36
37namespace OpenSim.Tests.Common
38{
39 /// <summary>
40 /// This class enables regression testing of the LLUDPServer by allowing us to intercept outgoing data.
41 /// </summary>
42 public class TestLLUDPServer : LLUDPServer
43 {
44 public List<Packet> PacketsSent { get; private set; }
45
46 public TestLLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager)
47 : base(listenIP, ref port, proxyPortOffsetParm, allow_alternate_port, configSource, circuitManager)
48 {
49 PacketsSent = new List<Packet>();
50 }
51
52 public override void SendAckImmediate(IPEndPoint remoteEndpoint, PacketAckPacket ack)
53 {
54 PacketsSent.Add(ack);
55 }
56
57 public override void SendPacket(
58 LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method)
59 {
60 PacketsSent.Add(packet);
61 }
62
63 public void ClientOutgoingPacketHandler(IClientAPI client, bool resendUnacked, bool sendAcks, bool sendPing)
64 {
65 m_resendUnacked = resendUnacked;
66 m_sendAcks = sendAcks;
67 m_sendPing = sendPing;
68
69 ClientOutgoingPacketHandler(client);
70 }
71
72//// /// <summary>
73//// /// The chunks of data to pass to the LLUDPServer when it calls EndReceive
74//// /// </summary>
75//// protected Queue<ChunkSenderTuple> m_chunksToLoad = new Queue<ChunkSenderTuple>();
76//
77//// protected override void BeginReceive()
78//// {
79//// if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException)
80//// {
81//// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
82//// reusedEpSender = tuple.Sender;
83//// throw new SocketException();
84//// }
85//// }
86//
87//// protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
88//// {
89//// numBytes = 0;
90////
91//// //m_log.Debug("Queue size " + m_chunksToLoad.Count);
92////
93//// if (m_chunksToLoad.Count <= 0)
94//// return false;
95////
96//// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
97//// RecvBuffer = tuple.Data;
98//// numBytes = tuple.Data.Length;
99//// epSender = tuple.Sender;
100////
101//// return true;
102//// }
103//
104//// public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)
105//// {
106//// // Don't do anything just yet
107//// }
108//
109// /// <summary>
110// /// Signal that this chunk should throw an exception on Socket.BeginReceive()
111// /// </summary>
112// /// <param name="epSender"></param>
113// public void LoadReceiveWithBeginException(EndPoint epSender)
114// {
115// ChunkSenderTuple tuple = new ChunkSenderTuple(epSender);
116// tuple.BeginReceiveException = true;
117// m_chunksToLoad.Enqueue(tuple);
118// }
119//
120// /// <summary>
121// /// Load some data to be received by the LLUDPServer on the next receive call
122// /// </summary>
123// /// <param name="data"></param>
124// /// <param name="epSender"></param>
125// public void LoadReceive(byte[] data, EndPoint epSender)
126// {
127// m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender));
128// }
129//
130// /// <summary>
131// /// Load a packet to be received by the LLUDPServer on the next receive call
132// /// </summary>
133// /// <param name="packet"></param>
134// public void LoadReceive(Packet packet, EndPoint epSender)
135// {
136// LoadReceive(packet.ToBytes(), epSender);
137// }
138//
139// /// <summary>
140// /// Calls the protected asynchronous result method. This fires out all data chunks currently queued for send
141// /// </summary>
142// /// <param name="result"></param>
143// public void ReceiveData(IAsyncResult result)
144// {
145// // Doesn't work the same way anymore
146//// while (m_chunksToLoad.Count > 0)
147//// OnReceivedData(result);
148// }
149 }
150
151 /// <summary>
152 /// Record the data and sender tuple
153 /// </summary>
154 public class ChunkSenderTuple
155 {
156 public byte[] Data;
157 public EndPoint Sender;
158 public bool BeginReceiveException;
159
160 public ChunkSenderTuple(byte[] data, EndPoint sender)
161 {
162 Data = data;
163 Sender = sender;
164 }
165
166 public ChunkSenderTuple(EndPoint sender)
167 {
168 Sender = sender;
169 }
170 }
171}