diff options
author | Justin Clark-Casey (justincc) | 2011-12-08 21:45:02 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-12-08 21:45:02 +0000 |
commit | 32d0ef89c6fbaf14e669e9dd3a8508bc817fbd52 (patch) | |
tree | 8cd3e37ea48bb5116d1441bde897e00533805b5d | |
parent | Add OpenSim.Region.ClientStack.LindenUDP.Tests.dll back into the test suite (diff) | |
download | opensim-SC_OLD-32d0ef89c6fbaf14e669e9dd3a8508bc817fbd52.zip opensim-SC_OLD-32d0ef89c6fbaf14e669e9dd3a8508bc817fbd52.tar.gz opensim-SC_OLD-32d0ef89c6fbaf14e669e9dd3a8508bc817fbd52.tar.bz2 opensim-SC_OLD-32d0ef89c6fbaf14e669e9dd3a8508bc817fbd52.tar.xz |
Extend TestAddClient() to check that the first packet received is an ack packet
3 files changed, 116 insertions, 93 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index ac21805..cef5f74 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | |||
@@ -328,7 +328,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
328 | /// The method to call if the packet is not acked by the client. If null, then a standard | 328 | /// The method to call if the packet is not acked by the client. If null, then a standard |
329 | /// resend of the packet is done. | 329 | /// resend of the packet is done. |
330 | /// </param> | 330 | /// </param> |
331 | public void SendPacket( | 331 | public virtual void SendPacket( |
332 | LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method) | 332 | LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method) |
333 | { | 333 | { |
334 | // CoarseLocationUpdate packets cannot be split in an automated way | 334 | // CoarseLocationUpdate packets cannot be split in an automated way |
@@ -928,6 +928,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
928 | // buffer.RemoteEndPoint, (DateTime.Now - startTime).Milliseconds); | 928 | // buffer.RemoteEndPoint, (DateTime.Now - startTime).Milliseconds); |
929 | } | 929 | } |
930 | 930 | ||
931 | /// <summary> | ||
932 | /// Send an ack immediately to the given endpoint. | ||
933 | /// </summary> | ||
934 | /// <remarks> | ||
935 | /// FIXME: Might be possible to use SendPacketData() like everything else, but this will require refactoring so | ||
936 | /// that we can obtain the UDPClient easily at this point. | ||
937 | /// </remarks> | ||
938 | /// <param name="remoteEndpoint"></param> | ||
939 | /// <param name="sequenceNumber"></param> | ||
931 | private void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber) | 940 | private void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber) |
932 | { | 941 | { |
933 | PacketAckPacket ack = new PacketAckPacket(); | 942 | PacketAckPacket ack = new PacketAckPacket(); |
@@ -936,6 +945,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
936 | ack.Packets[0] = new PacketAckPacket.PacketsBlock(); | 945 | ack.Packets[0] = new PacketAckPacket.PacketsBlock(); |
937 | ack.Packets[0].ID = sequenceNumber; | 946 | ack.Packets[0].ID = sequenceNumber; |
938 | 947 | ||
948 | SendAckImmediate(remoteEndpoint, ack); | ||
949 | } | ||
950 | |||
951 | public virtual void SendAckImmediate(IPEndPoint remoteEndpoint, PacketAckPacket ack) | ||
952 | { | ||
939 | byte[] packetData = ack.ToBytes(); | 953 | byte[] packetData = ack.ToBytes(); |
940 | int length = packetData.Length; | 954 | int length = packetData.Length; |
941 | 955 | ||
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs index c6a5b98..1457194 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs | |||
@@ -37,7 +37,7 @@ using OpenSim.Region.Framework.Scenes; | |||
37 | using OpenSim.Tests.Common; | 37 | using OpenSim.Tests.Common; |
38 | using OpenSim.Tests.Common.Mock; | 38 | using OpenSim.Tests.Common.Mock; |
39 | 39 | ||
40 | namespace OpenSim.Region.ClientStack.LindenUDP | 40 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests |
41 | { | 41 | { |
42 | /// <summary> | 42 | /// <summary> |
43 | /// This will contain basic tests for the LindenUDP client stack | 43 | /// This will contain basic tests for the LindenUDP client stack |
@@ -167,8 +167,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
167 | uint port = 0; | 167 | uint port = 0; |
168 | AgentCircuitManager acm = scene.AuthenticateHandler; | 168 | AgentCircuitManager acm = scene.AuthenticateHandler; |
169 | 169 | ||
170 | LLUDPServer llUdpServer | 170 | TestLLUDPServer llUdpServer |
171 | = new LLUDPServer(IPAddress.Any, ref port, 0, false, new IniConfigSource(), acm); | 171 | = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, new IniConfigSource(), acm); |
172 | llUdpServer.AddScene(scene); | 172 | llUdpServer.AddScene(scene); |
173 | 173 | ||
174 | UseCircuitCodePacket uccp = new UseCircuitCodePacket(); | 174 | UseCircuitCodePacket uccp = new UseCircuitCodePacket(); |
@@ -201,6 +201,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
201 | // Should succeed now | 201 | // Should succeed now |
202 | ScenePresence sp = scene.GetScenePresence(myAgentUuid); | 202 | ScenePresence sp = scene.GetScenePresence(myAgentUuid); |
203 | Assert.That(sp.UUID, Is.EqualTo(myAgentUuid)); | 203 | Assert.That(sp.UUID, Is.EqualTo(myAgentUuid)); |
204 | |||
205 | // FIXME: We're still replying to an ack when the client is not authorized, which is not correct behaviour. | ||
206 | Assert.That(llUdpServer.PacketsSent.Count, Is.EqualTo(2)); | ||
207 | |||
208 | Packet packet = llUdpServer.PacketsSent[1]; | ||
209 | Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket))); | ||
210 | |||
211 | PacketAckPacket ackPacket = packet as PacketAckPacket; | ||
212 | Assert.That(ackPacket.Packets.Length, Is.EqualTo(1)); | ||
213 | Assert.That(ackPacket.Packets[0].ID, Is.EqualTo(0)); | ||
204 | } | 214 | } |
205 | 215 | ||
206 | // /// <summary> | 216 | // /// <summary> |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs index dd7999a..0302385 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs | |||
@@ -36,107 +36,106 @@ using OpenSim.Framework; | |||
36 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | 36 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests |
37 | { | 37 | { |
38 | /// <summary> | 38 | /// <summary> |
39 | /// This class enables synchronous testing of the LLUDPServer by allowing us to load our own data into the end | 39 | /// This class enables regression testing of the LLUDPServer by allowing us to intercept outgoing data. |
40 | /// receive event | ||
41 | /// </summary> | 40 | /// </summary> |
42 | public class TestLLUDPServer : LLUDPServer | 41 | public class TestLLUDPServer : LLUDPServer |
43 | { | 42 | { |
43 | public List<Packet> PacketsSent { get; private set; } | ||
44 | |||
44 | public TestLLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) | 45 | public TestLLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) |
45 | : base(listenIP, ref port, proxyPortOffsetParm, allow_alternate_port, configSource, circuitManager) | 46 | : base(listenIP, ref port, proxyPortOffsetParm, allow_alternate_port, configSource, circuitManager) |
46 | {} | ||
47 | |||
48 | /// <summary> | ||
49 | /// The chunks of data to pass to the LLUDPServer when it calls EndReceive | ||
50 | /// </summary> | ||
51 | protected Queue<ChunkSenderTuple> m_chunksToLoad = new Queue<ChunkSenderTuple>(); | ||
52 | |||
53 | // protected override void BeginReceive() | ||
54 | // { | ||
55 | // if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException) | ||
56 | // { | ||
57 | // ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
58 | // reusedEpSender = tuple.Sender; | ||
59 | // throw new SocketException(); | ||
60 | // } | ||
61 | // } | ||
62 | |||
63 | // protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender) | ||
64 | // { | ||
65 | // numBytes = 0; | ||
66 | // | ||
67 | // //m_log.Debug("Queue size " + m_chunksToLoad.Count); | ||
68 | // | ||
69 | // if (m_chunksToLoad.Count <= 0) | ||
70 | // return false; | ||
71 | // | ||
72 | // ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
73 | // RecvBuffer = tuple.Data; | ||
74 | // numBytes = tuple.Data.Length; | ||
75 | // epSender = tuple.Sender; | ||
76 | // | ||
77 | // return true; | ||
78 | // } | ||
79 | |||
80 | // public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode) | ||
81 | // { | ||
82 | // // Don't do anything just yet | ||
83 | // } | ||
84 | |||
85 | /// <summary> | ||
86 | /// Signal that this chunk should throw an exception on Socket.BeginReceive() | ||
87 | /// </summary> | ||
88 | /// <param name="epSender"></param> | ||
89 | public void LoadReceiveWithBeginException(EndPoint epSender) | ||
90 | { | ||
91 | ChunkSenderTuple tuple = new ChunkSenderTuple(epSender); | ||
92 | tuple.BeginReceiveException = true; | ||
93 | m_chunksToLoad.Enqueue(tuple); | ||
94 | } | ||
95 | |||
96 | /// <summary> | ||
97 | /// Load some data to be received by the LLUDPServer on the next receive call | ||
98 | /// </summary> | ||
99 | /// <param name="data"></param> | ||
100 | /// <param name="epSender"></param> | ||
101 | public void LoadReceive(byte[] data, EndPoint epSender) | ||
102 | { | 47 | { |
103 | m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender)); | 48 | PacketsSent = new List<Packet>(); |
104 | } | 49 | } |
105 | 50 | ||
106 | /// <summary> | 51 | public override void SendAckImmediate(IPEndPoint remoteEndpoint, PacketAckPacket ack) |
107 | /// Load a packet to be received by the LLUDPServer on the next receive call | ||
108 | /// </summary> | ||
109 | /// <param name="packet"></param> | ||
110 | public void LoadReceive(Packet packet, EndPoint epSender) | ||
111 | { | 52 | { |
112 | LoadReceive(packet.ToBytes(), epSender); | 53 | PacketsSent.Add(ack); |
113 | } | 54 | } |
114 | 55 | ||
115 | /// <summary> | 56 | public override void SendPacket( |
116 | /// Calls the protected asynchronous result method. This fires out all data chunks currently queued for send | 57 | LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method) |
117 | /// </summary> | ||
118 | /// <param name="result"></param> | ||
119 | public void ReceiveData(IAsyncResult result) | ||
120 | { | 58 | { |
121 | // Doesn't work the same way anymore | 59 | PacketsSent.Add(packet); |
122 | // while (m_chunksToLoad.Count > 0) | ||
123 | // OnReceivedData(result); | ||
124 | } | 60 | } |
125 | |||
126 | /// <summary> | ||
127 | /// Has a circuit with the given code been established? | ||
128 | /// </summary> | ||
129 | /// <param name="circuitCode"></param> | ||
130 | /// <returns></returns> | ||
131 | public bool HasCircuit(uint circuitCode) | ||
132 | { | ||
133 | // lock (clientCircuits_reverse) | ||
134 | // { | ||
135 | // return clientCircuits_reverse.ContainsKey(circuitCode); | ||
136 | // } | ||
137 | 61 | ||
138 | return true; | 62 | //// /// <summary> |
139 | } | 63 | //// /// The chunks of data to pass to the LLUDPServer when it calls EndReceive |
64 | //// /// </summary> | ||
65 | //// protected Queue<ChunkSenderTuple> m_chunksToLoad = new Queue<ChunkSenderTuple>(); | ||
66 | // | ||
67 | //// protected override void BeginReceive() | ||
68 | //// { | ||
69 | //// if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException) | ||
70 | //// { | ||
71 | //// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
72 | //// reusedEpSender = tuple.Sender; | ||
73 | //// throw new SocketException(); | ||
74 | //// } | ||
75 | //// } | ||
76 | // | ||
77 | //// protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender) | ||
78 | //// { | ||
79 | //// numBytes = 0; | ||
80 | //// | ||
81 | //// //m_log.Debug("Queue size " + m_chunksToLoad.Count); | ||
82 | //// | ||
83 | //// if (m_chunksToLoad.Count <= 0) | ||
84 | //// return false; | ||
85 | //// | ||
86 | //// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
87 | //// RecvBuffer = tuple.Data; | ||
88 | //// numBytes = tuple.Data.Length; | ||
89 | //// epSender = tuple.Sender; | ||
90 | //// | ||
91 | //// return true; | ||
92 | //// } | ||
93 | // | ||
94 | //// public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode) | ||
95 | //// { | ||
96 | //// // Don't do anything just yet | ||
97 | //// } | ||
98 | // | ||
99 | // /// <summary> | ||
100 | // /// Signal that this chunk should throw an exception on Socket.BeginReceive() | ||
101 | // /// </summary> | ||
102 | // /// <param name="epSender"></param> | ||
103 | // public void LoadReceiveWithBeginException(EndPoint epSender) | ||
104 | // { | ||
105 | // ChunkSenderTuple tuple = new ChunkSenderTuple(epSender); | ||
106 | // tuple.BeginReceiveException = true; | ||
107 | // m_chunksToLoad.Enqueue(tuple); | ||
108 | // } | ||
109 | // | ||
110 | // /// <summary> | ||
111 | // /// Load some data to be received by the LLUDPServer on the next receive call | ||
112 | // /// </summary> | ||
113 | // /// <param name="data"></param> | ||
114 | // /// <param name="epSender"></param> | ||
115 | // public void LoadReceive(byte[] data, EndPoint epSender) | ||
116 | // { | ||
117 | // m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender)); | ||
118 | // } | ||
119 | // | ||
120 | // /// <summary> | ||
121 | // /// Load a packet to be received by the LLUDPServer on the next receive call | ||
122 | // /// </summary> | ||
123 | // /// <param name="packet"></param> | ||
124 | // public void LoadReceive(Packet packet, EndPoint epSender) | ||
125 | // { | ||
126 | // LoadReceive(packet.ToBytes(), epSender); | ||
127 | // } | ||
128 | // | ||
129 | // /// <summary> | ||
130 | // /// Calls the protected asynchronous result method. This fires out all data chunks currently queued for send | ||
131 | // /// </summary> | ||
132 | // /// <param name="result"></param> | ||
133 | // public void ReceiveData(IAsyncResult result) | ||
134 | // { | ||
135 | // // Doesn't work the same way anymore | ||
136 | //// while (m_chunksToLoad.Count > 0) | ||
137 | //// OnReceivedData(result); | ||
138 | // } | ||
140 | } | 139 | } |
141 | 140 | ||
142 | /// <summary> | 141 | /// <summary> |