Exemple #1
0
    static void test_generate_ack_bits()
    {
        Log("test_generate_ack_bits");
        const int Size            = 256;
        var       receivedPackets = new SequenceBuffer <TestPacketData>(Size);
        ushort    ack             = 0xFFFF;
        uint      ack_bits        = 0xFFFFFFFF;

        GenerateAckBits(receivedPackets, out ack, out ack_bits);
        IsTrue(ack == 0xFFFF);
        IsTrue(ack_bits == 0);

        for (int i = 0; i <= Size; ++i)
        {
            receivedPackets.Insert((ushort)i);
        }

        GenerateAckBits(receivedPackets, out ack, out ack_bits);
        IsTrue(ack == Size);
        IsTrue(ack_bits == 0xFFFFFFFF);

        receivedPackets.Reset();
        ushort[] input_acks = { 1, 5, 9, 11 };

        for (int i = 0; i < input_acks.Length; ++i)
        {
            receivedPackets.Insert(input_acks[i]);
        }

        GenerateAckBits(receivedPackets, out ack, out ack_bits);
        IsTrue(ack == 11);
        IsTrue(ack_bits == (1 | (1 << (11 - 9)) | (1 << (11 - 5)) | (1 << (11 - 1))));
    }
 public void Reset()
 {
     id       = 0;
     ackCount = 0;
     sentPackets.Reset();
     receivedPackets.Reset();
 }
Exemple #3
0
    public void Reset()
    {
        Profiler.BeginSample("DeltaBuffer.Reset");
        buffer.Reset();

        for (int i = 0; i < buffer.size; ++i)
        {
            buffer.entries[i].resetId = 0;
            buffer.entries[i].count   = 0;
        }
        Profiler.EndSample();
    }
Exemple #4
0
    static void test_sequence_buffer()
    {
        Log("test_sequence_buffer");
        const int Size   = 256;
        var       buffer = new SequenceBuffer <TestPacketData>(Size);

        for (int i = 0; i < Size; ++i)
        {
            TestPacketData entry;
            entry.sequence = 0;
            IsTrue(buffer.Exists((ushort)i) == false);
            IsTrue(buffer.Available((ushort)i) == true);
            IsTrue(buffer.Get((ushort)i) == -1);
        }

        for (int i = 0; i <= Size * 4; ++i)
        {
            int index = buffer.Insert((ushort)i);
            IsTrue(index != -1);
            IsTrue(buffer.id == i + 1);
            buffer.entries[index].sequence = (ushort)i;
        }

        for (int i = 0; i <= Size; ++i)
        {
            int index = buffer.Insert((ushort)i); //note: outside bounds!
            IsTrue(index == -1);
        }

        ushort sequence = Size * 4;

        for (int i = 0; i < Size; ++i)
        {
            int index = buffer.Get(sequence);
            IsTrue(index >= 0);
            IsTrue(index < Size);
            IsTrue(buffer.entries[index].sequence == sequence);
            sequence--;
        }

        buffer.Reset();
        IsTrue(buffer.id == 0);

        for (int i = 0; i < Size; ++i)
        {
            IsTrue(buffer.Exists((ushort)i) == false);
            IsTrue(buffer.Available((ushort)i) == true);
            IsTrue(buffer.Get((ushort)i) == -1);
        }
    }