Пример #1
0
 internal bool IsSentOut(long sequenceNumber)
 {
     return(SequenceNumber.Compare(largestSentSequenceNumber, sequenceNumber) >= 0);
 }
Пример #2
0
        protected void OnDataPacketReceived(DataPacket dp)
        {
            long currentSequenceNumber = dp.PacketSequenceNumber;

            //for TESTING : check whether to drop this packet
//		n++;
//		//if(dropRate>0 && n % dropRate == 0){
//			if(n % 1111 == 0){
//				logger.info("**** TESTING:::: DROPPING PACKET "+currentSequenceNumber+" FOR TESTING");
//				return;
//			}
//		//}
            bool OK = session.Socket.GetInputStream().HaveNewData(currentSequenceNumber, dp.Buffer);

            if (!OK)
            {
                //need to drop packet...
                return;
            }

            long currentDataPacketArrivalTime = Util.getCurrentTime();

            /*(4).if the seqNo of the current data packet is 16n+1,record the
             * time interval between this packet and the last data packet
             * in the packet pair window*/
            if ((currentSequenceNumber % 16) == 1 && lastDataPacketArrivalTime > 0)
            {
                long interval = currentDataPacketArrivalTime - lastDataPacketArrivalTime;
                packetPairWindow.Add(interval);
            }

            //(5).record the packet arrival time in the PKT History Window.
            packetHistoryWindow.Add(currentDataPacketArrivalTime);


            //store current time
            lastDataPacketArrivalTime = currentDataPacketArrivalTime;


            //(6).number of detected lossed packet

            /*(6.a).if the number of the current data packet is greater than LSRN+1,
             *      put all the sequence numbers between (but excluding) these two values
             *      into the receiver's loss list and send them to the sender in an NAK packet*/
            if (SequenceNumber.Compare(currentSequenceNumber, largestReceivedSeqNumber + 1) > 0)
            {
                SendNAK(currentSequenceNumber);
            }
            else if (SequenceNumber.Compare(currentSequenceNumber, largestReceivedSeqNumber) < 0)
            {
                /*(6.b).if the sequence number is less than LRSN,remove it from
                 * the receiver's loss list
                 */
                receiverLossList.remove(currentSequenceNumber);
            }

            statistics.incNumberOfReceivedDataPackets();

            //(7).Update the LRSN
            if (SequenceNumber.Compare(currentSequenceNumber, largestReceivedSeqNumber) > 0)
            {
                largestReceivedSeqNumber = currentSequenceNumber;
            }

            //(8) need to send an ACK? Some cc algorithms use this
            if (ackInterval > 0)
            {
                if (n % ackInterval == 0)
                {
                    ProcessACKEvent(false);
                }
            }
        }
Пример #3
0
 internal bool HaveAcknowledgementFor(long sequenceNumber)
 {
     return(SequenceNumber.Compare(sequenceNumber, lastAckSequenceNumber) <= 0);
 }