Exemplo n.º 1
0
        public void TrackingModuleTest()
        {
            RUDPDeliverTrackingModule trackingModule = new RUDPDeliverTrackingModule();

            ushort seed          = 65520;
            ushort payloadsCount = 0;

            trackingModule.Reset(65520);

            for (ushort i = seed; i != 20; i++)
            {
                RUDPPayload newPayload = new RUDPPayload(RUDPPayload.PAYLOAD_TAG.DELIVERY_NOFIFY, 0);
                newPayload.Packet = this.emptyPacket;
                trackingModule.PrepareToDeliver(newPayload);
                payloadsCount++;
            }

            // 몇가지 Seq를 뺀 Ack를 만들어서 trackingModule에서 Ack를 처리하게 해야함
            // 그리고 결과를 처음 빠트린 Ack와 정상 ACk와 일치하는지 검증

            ushort halfPoint = seed;

            halfPoint += (ushort)(payloadsCount / 2);

            AckRange ackR = new AckRange(halfPoint, (ushort)(payloadsCount / 2));

            trackingModule.ProcessAckRange(ackR);

            ushort[] success = trackingModule.GetAndClearSuccessPayloadSeqNums();
            ushort[] fail    = trackingModule.GetAndClearLossPayloadSeqNums();

            Assert.IsTrue(ackR.AckCount == success.Length);
            Assert.IsTrue((payloadsCount - ackR.AckCount) == fail.Length);

            for (int i = 0; i < ackR.AckCount; i++)   //성공한 Ack
            {
                Assert.IsTrue((ackR.StartNum + i) == success[i]);
            }

            ushort start = seed;

            for (ushort i = 0; i < (payloadsCount - ackR.AckCount); i++)   //실패한 Ack
            {
                Assert.IsTrue((ushort)start == fail[i]);
                start++;
            }
        }
Exemplo n.º 2
0
    private void OnReceivePayloads(Queue <RUDPPayload> payloads)
    {
        var iter = payloads.GetEnumerator();

        while (iter.MoveNext())
        {
            if (iter.Current.Packet != null)
            {
                switch (iter.Current.Tag)
                {
                case RUDPPayload.PAYLOAD_TAG.RAW: {
                    OnPacketReceive(iter.Current.Packet);
                    break;
                }

                case RUDPPayload.PAYLOAD_TAG.DELIVERY_NOFIFY: {
                    //Debug.Log(string.Format("DeliverNotify 패킷 받음 {0}", iter.Current.SequenceNumber));
                    if (this.deliverConfirmModule.JudgeIncomePayload(iter.Current))
                    {
                        OnPacketReceive(iter.Current.Packet);
                    }
                    break;
                }

                case RUDPPayload.PAYLOAD_TAG.ACK: {
                    AckRange currentAck = new AckRange(0, iter.Current.Packet.Pop_UInt16());
                    currentAck.StartNum = iter.Current.Packet.Pop_UInt16();
                    //Debug.Log(string.Format("Ack 받음 StartNum : {0}, Count : {1}", currentAck.StartNum, currentAck.AckCount));
                    deliverTrackingModule.ProcessAckRange(currentAck);
                    break;
                }

                case RUDPPayload.PAYLOAD_TAG.DISCONNECT: {
                    isDisable = true;
                    this.receiver.Disconnect();
                    this.sender.Disconnect(true, true);
                    OnDisconnect.Invoke();
                    break;
                }
                }
            }
        }
    }