예제 #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))));
    }
예제 #2
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);
        }
    }
    public PacketHeader AddUnackedPackets(ref PacketHeader header)
    {
        header.id = id;
        GenerateAckBits(receivedPackets, out header.ack, out header.ackBits);

        int entryId = sentPackets.Insert(id);

        IsTrue(entryId != -1);
        sentPackets.entries[entryId].isAcked = false;
        id++;

        return(header);
    }
예제 #4
0
    public bool AddPacket(ushort packetId, ushort resetId)
    {
        int id = buffer.Insert(packetId);

        if (id == -1)
        {
            return(false);
        }

        buffer.entries[id].resetId = resetId;
        buffer.entries[id].count   = 0;

        for (int i = 0; i < MaxCubes; ++i)
        {
            buffer.entries[id].priorityIds[i] = -1;
        }

        return(true);
    }
    public void AckPackets(ref PacketHeader h)
    {
        receivedPackets.Insert(h.id);

        for (int i = 0; i < 32; ++i)
        {
            if ((h.ackBits & 1) == 0)
            {
                h.ackBits >>= 1;
                continue;
            }

            var packetId = (ushort)(h.ack - i);
            int id       = sentPackets.Get(packetId);

            if (id != -1 && !sentPackets.entries[id].isAcked)
            {
                Ack(packetId);
                sentPackets.entries[id].isAcked = true;
            }
            h.ackBits >>= 1;
        }
    }