diff options
author | Justin Clark-Casey (justincc) | 2014-10-08 20:17:51 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-11-25 23:18:40 +0000 |
commit | 52370ac94de4f449645eb0471fab4cc515fccbe2 (patch) | |
tree | 1b920cad4f0416420a8fec9f804b1272bf92166e /OpenSim/Tests/Common/Mock/TestLLUDPServer.cs | |
parent | Fix recent regression in "debug lludp throttles get" command that stopped it ... (diff) | |
download | opensim-SC-52370ac94de4f449645eb0471fab4cc515fccbe2.zip opensim-SC-52370ac94de4f449645eb0471fab4cc515fccbe2.tar.gz opensim-SC-52370ac94de4f449645eb0471fab4cc515fccbe2.tar.bz2 opensim-SC-52370ac94de4f449645eb0471fab4cc515fccbe2.tar.xz |
refactor: Move test clientstack setup code out of BasicCircuitTests into OpenSim.Tests.Common.ClientStackHelpers
Diffstat (limited to 'OpenSim/Tests/Common/Mock/TestLLUDPServer.cs')
-rw-r--r-- | OpenSim/Tests/Common/Mock/TestLLUDPServer.cs | 171 |
1 files changed, 171 insertions, 0 deletions
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Net.Sockets; | ||
32 | using Nini.Config; | ||
33 | using OpenMetaverse.Packets; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Region.ClientStack.LindenUDP; | ||
36 | |||
37 | namespace 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 | } | ||