public void S2_DataTransfer_ClientReceiveData()
        {
            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Reliable, TransportMode.Lossy };
            foreach (TransportMode transportMode in transportModeArray)
            {
                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", transportMode);
                this.EstablishUDPConnection(transportMode, waitTime, true);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Send the first RDPEUDP Source packet");
                RdpeudpPacket packet = this.GetFirstValidUdpPacket(transportMode);
                this.SendPacket(transportMode, packet);

                #region Create Expect Ack Vectors

                List <AckVector> expectedAckVectors = new List <AckVector>();
                AckVector        ackVector          = new AckVector();
                ackVector.State  = VECTOR_ELEMENT_STATE.DATAGRAM_RECEIVED;
                ackVector.Length = (byte)(packet.sourceHeader.Value.snSourceStart - getSnInitialSequenceNumber(transportMode) - 1);
                expectedAckVectors.Add(ackVector);

                #endregion Create Expect Ack Vectors

                this.TestSite.Log.Add(LogEntryKind.Comment, "Expect RDP client to send an ACK packet to acknowledge the receipt");
                RdpeudpPacket ackpacket = WaitForACKPacket(transportMode, waitTime, expectedAckVectors.ToArray());
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK to acknowledge the receipt of source packet. Transport mode is {0}", transportMode);
            }
        }
        public void S2_DataTransfer_SequenceNumberWrapAround()
        {
            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Reliable, TransportMode.Lossy };

            CheckPlatformCompatibility(ref transportModeArray);

            CheckSecurityProtocolForMultitransport();

            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            foreach (TransportMode transportMode in transportModeArray)
            {
                DoUntilSucceed(() =>
                {
                    this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", transportMode);
                    initSequenceNumber = uint.MaxValue - 3;
                    this.EstablishUDPConnection(transportMode, waitTime, true);

                    this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} RDPEMT connection.", transportMode);
                    return(this.EstablishRdpemtConnection(transportMode, waitTime));
                },
                               this.waitTime * 5,
                               TimeSpan.FromSeconds(0.5),
                               "RDPEMT tunnel creation failed");

                if (getSourcePacketSequenceNumber(transportMode) > getSnInitialSequenceNumber(transportMode))
                {
                    this.TestSite.Log.Add(LogEntryKind.Comment, "Not wrap around yet, Send one RDPUDP packet.");
                    this.SendNextValidUdpPacket(transportMode);
                }

                this.TestSite.Log.Add(LogEntryKind.Comment, "Already wrap around, Send three RDPUDP packet again.");
                this.SendNextValidUdpPacket(transportMode);
                this.SendNextValidUdpPacket(transportMode);
                this.SendNextValidUdpPacket(transportMode);

                #region Create Expect Ack Vectors

                List <AckVector> expectedAckVectors = new List <AckVector>();
                AckVector        ackVector          = new AckVector();
                ackVector.State  = VECTOR_ELEMENT_STATE.DATAGRAM_RECEIVED;
                ackVector.Length = (byte)(getSourcePacketSequenceNumber(transportMode) + (uint.MaxValue - getSnInitialSequenceNumber(transportMode)));
                expectedAckVectors.Add(ackVector);

                #endregion Create Expect Ack Vectors

                this.TestSite.Log.Add(LogEntryKind.Comment, "Expect RDP client to send an ACK packet to acknowledge the receipt correctly");
                RdpeudpPacket ackpacket = WaitForACKPacket(transportMode, waitTime, expectedAckVectors.ToArray());
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK to correctly acknowledge the receipt of source packet. Transport mode is {0}", transportMode);
            }
        }
        public void S2_DataTransfer_AcknowledgeTest_AcknowlegeLossyPackage()
        {
            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Reliable, TransportMode.Lossy };

            foreach (TransportMode transportMode in transportModeArray)
            {
                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", transportMode);
                this.EstablishUDPConnection(transportMode, waitTime, true);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} RDPEMT connection.", transportMode);
                this.EstablishRdpemtConnection(transportMode, waitTime);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Send one RDPUDP packet.");
                this.SendNextValidUdpPacket(transportMode);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Send the second RDPUDP packet, don't really send it, it is as a lost packet");
                RdpeudpPacket losspacket = this.GetNextValidUdpPacket(transportMode);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Send the third and the forth RDPUDP packet.");
                this.SendNextValidUdpPacket(transportMode);
                this.SendNextValidUdpPacket(transportMode);

                #region Create Expect Ack Vectors

                List <AckVector> expectedAckVectors = new List <AckVector>();

                // All packet before the lost one are received.
                AckVector ackVector = new AckVector();
                ackVector.State  = VECTOR_ELEMENT_STATE.DATAGRAM_RECEIVED;
                ackVector.Length = (byte)(losspacket.sourceHeader.Value.snSourceStart - getSnInitialSequenceNumber(transportMode) - 2);
                expectedAckVectors.Add(ackVector);

                // One packet lost.
                ackVector        = new AckVector();
                ackVector.State  = VECTOR_ELEMENT_STATE.DATAGRAM_NOT_YET_RECEIVED;
                ackVector.Length = 0;
                expectedAckVectors.Add(ackVector);

                // Two packet received.
                ackVector        = new AckVector();
                ackVector.State  = VECTOR_ELEMENT_STATE.DATAGRAM_RECEIVED;
                ackVector.Length = 1;
                expectedAckVectors.Add(ackVector);

                #endregion Create Expect Ack Vectors

                // Expect an ACK packet with expected acknowledge information.
                this.TestSite.Log.Add(LogEntryKind.Comment, "expect an ACK packet with expected acknowledge information.");
                RdpeudpPacket ackpacket = WaitForACKPacket(transportMode, waitTime, expectedAckVectors.ToArray());
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK to acknowledge the receipt of source packets correctly, transport mode is {0}.", transportMode);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Send the second RDPUDP packet, which is lost before");
                this.SendPacket(transportMode, losspacket);

                #region Create Expect Ack Vectors

                expectedAckVectors.Clear();
                // All packet before the lost one are received.
                ackVector        = new AckVector();
                ackVector.State  = VECTOR_ELEMENT_STATE.DATAGRAM_RECEIVED;
                ackVector.Length = (byte)(losspacket.sourceHeader.Value.snSourceStart - getSnInitialSequenceNumber(transportMode) - 2);

                // The lost one and the next two packed are received too.
                ackVector.Length += 3;
                expectedAckVectors.Add(ackVector);

                #endregion

                // Expect an ACK packet with acknowledge all packets recieved.
                this.TestSite.Log.Add(LogEntryKind.Comment, "expect an ACK packet with acknowledge all packets received.");
                ackpacket = WaitForACKPacket(transportMode, waitTime, expectedAckVectors.ToArray());
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK to acknowledge the receipt of source packets correctly, transport mode is {0}.", transportMode);
            }
        }