Exemplo n.º 1
0
 /// <summary>
 /// create a receiver with a valid {@link UDTSession}
 /// </summary>
 /// <param name="session"></param>
 /// <param name="endpoint"></param>
 public UDTReceiver(UDTSession session, UDPEndPoint endpoint)
 {
     this.roundTripTimeVar = roundTripTime / 2;
     this.endpoint         = endpoint;
     this.session          = session;
     //( System.DateTime.UtcNow.Ticks - new DateTime(1970, 1, 1, 0, 0, 0).Ticks)/10000;
     //如果要得到Java中 System.currentTimeMillis() 一样的结果,就可以写成 上面那样,也可以这样写:
     // TimeSpan ts=new TimeSpan( System.DateTime.UtcNow.Ticks - new DateTime(1970, 1, 1, 0, 0, 0).Ticks);
     //(long)ts.TotalMilliseconds;
     this.sessionUpSince = (long)ts.TotalMilliseconds;
     this.statistics     = session.getStatistics();
     if (!session.isReady())
     {
         Log.Write(this.ToString(), "UDTSession is not ready.");
     }
     ackHistoryWindow         = new AckHistoryWindow(16);
     packetHistoryWindow      = new PacketHistoryWindow(16);
     receiverLossList         = new ReceiverLossList();
     packetPairWindow         = new PacketPairWindow(16);
     largestReceivedSeqNumber = (int)session.getInitialSequenceNumber() - 1;
     bufferSize      = session.getReceiveBufferSize();
     handoffQueue    = new Queue <UDTPacket>(4 * session.getFlowWindowSize());
     storeStatistics = false;      //Boolean.getBoolean("udt.receiver.storeStatistics");
     initMetrics();
     start();
 }
        /* (non-Javadoc)
         * @see udt.CongestionControl#onACK(long)
         */
        public void onACK(long ackSeqno)
        {
            //increase window during slow start
            if (slowStartPhase)
            {
                congestionWindowSize += ackSeqno - lastAckSeqNumber;
                lastAckSeqNumber      = ackSeqno;
                //but not beyond a maximum size
                if (congestionWindowSize > session.getFlowWindowSize())
                {
                    slowStartPhase = false;
                    if (packetArrivalRate > 0)
                    {
                        packetSendingPeriod = 1000000.0 / packetArrivalRate;
                    }
                    else
                    {
                        packetSendingPeriod = (double)congestionWindowSize / (roundTripTime + Util.getSYNTimeD());
                    }
                }
            }
            else
            {
                //1.if it is  not in slow start phase,set the congestion window size
                //to the product of packet arrival rate and(rtt +SYN)
                double A = packetArrivalRate / 1000000.0 * (roundTripTime + Util.getSYNTimeD());
                congestionWindowSize = (long)A + 16;
                Log.Write(this.ToString(), "receive rate " + packetArrivalRate + " rtt " + roundTripTime + " set to window size: " + (A + 16));
            }

            //no rate increase during slow start
            if (slowStartPhase)
            {
                return;
            }

            //no rate increase "immediately" after a NAK
            if (loss)
            {
                loss = false;
                return;
            }

            //4. compute the increase in sent packets for the next SYN period
            double numOfIncreasingPacket = computeNumOfIncreasingPacket();

            //5. update the send period
            double factor = Util.getSYNTimeD() / (packetSendingPeriod * numOfIncreasingPacket + Util.getSYNTimeD());

            packetSendingPeriod = factor * packetSendingPeriod;
            //packetSendingPeriod=0.995*packetSendingPeriod;

            statistics.setSendPeriod(packetSendingPeriod);
        }
Exemplo n.º 3
0
 public UDTSender(UDTSession session, UDPEndPoint endpoint)
 {
     if (!session.isReady())
     {
         Log.Write(this.ToString(), "UDTSession is not ready.");
     }
     this.endpoint         = endpoint;
     this.session          = session;
     statistics            = session.getStatistics();
     senderLossList        = new SenderLossList();
     sendBuffer            = new Dictionary <long, DataPacket>(session.getFlowWindowSize());
     sendQueue             = new Queue <DataPacket>(1000);
     lastAckSequenceNumber = (int)session.getInitialSequenceNumber();
     currentSequenceNumber = (int)session.getInitialSequenceNumber() - 1;
     waitForAckLatch.Set(new CountDownLatch(1));
     waitForSeqAckLatch.Set(new CountDownLatch(1));
     storeStatistics = false;       //Boolean.getBoolean("udt.sender.storeStatistics");
     initMetrics();
     doStart();
 }