public void FragmentWithTSNWrap() { SctpDataReceiver receiver = new SctpDataReceiver(0, 0, uint.MaxValue - 2); SctpDataChunk chunk1 = new SctpDataChunk(false, true, false, uint.MaxValue - 2, 0, 0, 0, new byte[] { 0x00 }); SctpDataChunk chunk2 = new SctpDataChunk(false, false, false, uint.MaxValue - 1, 0, 0, 0, new byte[] { 0x01 }); SctpDataChunk chunk3 = new SctpDataChunk(false, false, false, uint.MaxValue, 0, 0, 0, new byte[] { 0x02 }); SctpDataChunk chunk4 = new SctpDataChunk(false, false, false, 0, 0, 0, 0, new byte[] { 0x03 }); SctpDataChunk chunk5 = new SctpDataChunk(false, false, true, 1, 0, 0, 0, new byte[] { 0x04 }); var sFrames1 = receiver.OnDataChunk(chunk1); Assert.Equal(uint.MaxValue - 2, receiver.CumulativeAckTSN); var sFrames2 = receiver.OnDataChunk(chunk2); Assert.Equal(uint.MaxValue - 1, receiver.CumulativeAckTSN); var sFrames3 = receiver.OnDataChunk(chunk3); Assert.Equal(uint.MaxValue, receiver.CumulativeAckTSN); var sFrames4 = receiver.OnDataChunk(chunk4); Assert.Equal(0U, receiver.CumulativeAckTSN); var sFrames5 = receiver.OnDataChunk(chunk5); Assert.Equal(1U, receiver.CumulativeAckTSN); Assert.Empty(sFrames1); Assert.Empty(sFrames2); Assert.Empty(sFrames3); Assert.Empty(sFrames4); Assert.Single(sFrames5); Assert.Equal("0001020304", sFrames5.Single().UserData.HexStr()); Assert.Equal(0, receiver.ForwardTSNCount); }
public void SinglePacketFrame() { SctpDataReceiver receiver = new SctpDataReceiver(0, 0, 0); SctpDataChunk chunk = new SctpDataChunk(false, true, true, 0, 0, 0, 0, new byte[] { 0x00 }); var sortedFrames = receiver.OnDataChunk(chunk); Assert.Single(sortedFrames); Assert.Equal("00", sortedFrames.Single().UserData.HexStr()); Assert.Equal(0U, receiver.CumulativeAckTSN); Assert.Equal(0, receiver.ForwardTSNCount); }
public void FragmentWithTSNWrapAndOutOfOrder() { SctpDataReceiver receiver = new SctpDataReceiver(0, 0, uint.MaxValue - 2); SctpDataChunk chunk1 = new SctpDataChunk(true, true, false, uint.MaxValue - 2, 0, 0, 0, new byte[] { 0x00 }); SctpDataChunk chunk2 = new SctpDataChunk(true, false, false, uint.MaxValue - 1, 0, 0, 0, new byte[] { 0x01 }); SctpDataChunk chunk3 = new SctpDataChunk(true, false, false, uint.MaxValue, 0, 0, 0, new byte[] { 0x02 }); SctpDataChunk chunk4 = new SctpDataChunk(true, false, false, 0, 0, 0, 0, new byte[] { 0x03 }); SctpDataChunk chunk5 = new SctpDataChunk(true, false, true, 1, 0, 0, 0, new byte[] { 0x04 }); // Intersperse a couple of full chunks in the middle of the fragmented chunk. SctpDataChunk chunk6 = new SctpDataChunk(true, true, true, 6, 0, 0, 0, new byte[] { 0x06 }); SctpDataChunk chunk9 = new SctpDataChunk(true, true, true, 9, 0, 0, 0, new byte[] { 0x09 }); var sframes9 = receiver.OnDataChunk(chunk9); Assert.Null(receiver.CumulativeAckTSN); var sframes1 = receiver.OnDataChunk(chunk1); Assert.Equal(uint.MaxValue - 2, receiver.CumulativeAckTSN); var sframes2 = receiver.OnDataChunk(chunk2); Assert.Equal(uint.MaxValue - 1, receiver.CumulativeAckTSN); var sframes3 = receiver.OnDataChunk(chunk3); Assert.Equal(uint.MaxValue, receiver.CumulativeAckTSN); var sframes6 = receiver.OnDataChunk(chunk6); Assert.Equal(uint.MaxValue, receiver.CumulativeAckTSN); var sframes4 = receiver.OnDataChunk(chunk4); Assert.Equal(0U, receiver.CumulativeAckTSN); var sframes5 = receiver.OnDataChunk(chunk5); Assert.Equal(1U, receiver.CumulativeAckTSN); Assert.Empty(sframes1); Assert.Empty(sframes2); Assert.Empty(sframes3); Assert.Empty(sframes4); Assert.Single(sframes6); Assert.Single(sframes9); Assert.Single(sframes5); Assert.Equal("0001020304", sframes5.Single().UserData.HexStr()); Assert.Equal(2, receiver.ForwardTSNCount); }
public void CheckExpiryWithSinglePacketChunksUnordered() { uint tsn = uint.MaxValue - 3; uint receiveWindow = 8; uint mtu = 1; SctpDataReceiver receiver = new SctpDataReceiver(receiveWindow, mtu, tsn); for (int i = 0; i < 50; i++) { SctpDataChunk chunk = new SctpDataChunk(true, true, true, tsn++, 0, 0, 0, new byte[] { 0x55 }); var sortedFrames = receiver.OnDataChunk(chunk); Assert.Single(sortedFrames); Assert.Equal("55", sortedFrames.Single().UserData.HexStr()); Assert.Equal(0, receiver.ForwardTSNCount); Assert.Equal(tsn - 1, receiver.CumulativeAckTSN); } }
public void ThreeStreamPackets() { SctpDataReceiver receiver = new SctpDataReceiver(0, 0, 0); SctpDataChunk chunk1 = new SctpDataChunk(false, true, true, 0, 0, 0, 0, new byte[] { 0x00 }); SctpDataChunk chunk2 = new SctpDataChunk(false, true, true, 1, 0, 1, 0, new byte[] { 0x01 }); SctpDataChunk chunk3 = new SctpDataChunk(false, true, true, 2, 0, 2, 0, new byte[] { 0x02 }); var sortFrames1 = receiver.OnDataChunk(chunk1); var sortFrames2 = receiver.OnDataChunk(chunk2); var sortFrames3 = receiver.OnDataChunk(chunk3); Assert.Single(sortFrames1); Assert.Equal(0, sortFrames1.Single().StreamSeqNum); Assert.Equal("00", sortFrames1.Single().UserData.HexStr()); Assert.Single(sortFrames2); Assert.Equal(1, sortFrames2.Single().StreamSeqNum); Assert.Equal("01", sortFrames2.Single().UserData.HexStr()); Assert.Single(sortFrames3); Assert.Equal(2, sortFrames3.Single().StreamSeqNum); Assert.Equal("02", sortFrames3.Single().UserData.HexStr()); Assert.Equal(0, receiver.ForwardTSNCount); }
public void ThreeFragmentsOutOfOrder() { SctpDataReceiver receiver = new SctpDataReceiver(0, 0, 0); SctpDataChunk chunk1 = new SctpDataChunk(false, true, false, 0, 0, 0, 0, new byte[] { 0x00 }); SctpDataChunk chunk2 = new SctpDataChunk(false, false, false, 1, 0, 0, 0, new byte[] { 0x01 }); SctpDataChunk chunk3 = new SctpDataChunk(false, false, true, 2, 0, 0, 0, new byte[] { 0x02 }); var sortFrames1 = receiver.OnDataChunk(chunk1); Assert.Equal(0U, receiver.CumulativeAckTSN); var sortFrames2 = receiver.OnDataChunk(chunk3); Assert.Equal(0U, receiver.CumulativeAckTSN); var sortFrames3 = receiver.OnDataChunk(chunk2); Assert.Equal(2U, receiver.CumulativeAckTSN); Assert.Empty(sortFrames1); Assert.Empty(sortFrames2); Assert.Single(sortFrames3); Assert.Equal("000102", sortFrames3.Single().UserData.HexStr()); Assert.Equal(0, receiver.ForwardTSNCount); }
public void StreamPacketsReceviedOutOfOrder() { SctpDataReceiver receiver = new SctpDataReceiver(0, 0, uint.MaxValue); SctpDataChunk chunk0 = new SctpDataChunk(false, true, true, uint.MaxValue, 0, ushort.MaxValue, 0, new byte[] { 0x00 }); SctpDataChunk chunk1 = new SctpDataChunk(false, true, true, 0, 0, 0, 0, new byte[] { 0x00 }); SctpDataChunk chunk2 = new SctpDataChunk(false, true, true, 1, 0, 1, 0, new byte[] { 0x01 }); SctpDataChunk chunk3 = new SctpDataChunk(false, true, true, 2, 0, 2, 0, new byte[] { 0x02 }); var sortFrames0 = receiver.OnDataChunk(chunk0); var sortFrames1 = receiver.OnDataChunk(chunk3); var sortFrames2 = receiver.OnDataChunk(chunk2); var sortFrames3 = receiver.OnDataChunk(chunk1); Assert.Single(sortFrames0); Assert.Empty(sortFrames1); Assert.Empty(sortFrames2); Assert.Equal(3, sortFrames3.Count); Assert.Equal(0, sortFrames3.First().StreamSeqNum); Assert.Equal("00", sortFrames3.First().UserData.HexStr()); Assert.Equal(2, sortFrames3.Last().StreamSeqNum); Assert.Equal("02", sortFrames3.Last().UserData.HexStr()); Assert.Equal(0, receiver.ForwardTSNCount); }