protected void ProcessUDTPacket(IUDTPacket p) { //(3).Check the packet type and process it according to this. if (!p.IsControlPacket()) { DataPacket dp = (DataPacket)p; if (storeStatistics) { dataPacketInterval.End(); dataProcessTime.Begin(); } OnDataPacketReceived(dp); if (storeStatistics) { dataProcessTime.End(); dataPacketInterval.Begin(); } } else if (p.GetControlPacketType() == (int)ControlPacketType.ACK2) { Acknowledgment2 ack2 = (Acknowledgment2)p; onAck2PacketReceived(ack2); } else if (p is Shutdown) { OnShutdown(); } }
/* * packets are written by the endpoint */ internal void Receive(IUDTPacket p) { if (storeStatistics) { dgReceiveInterval.End(); } handoffQueue.Add(p); if (storeStatistics) { dgReceiveInterval.Begin(); } }
/** * sends the given data packet, storing the relevant information * * @param data * @throws IOException * @throws InterruptedException */ private void Send(DataPacket p) { lock (sendLock){ if (storeStatistics) { dgSendInterval.End(); dgSendTime.Begin(); } endpoint.DoSend(p); if (storeStatistics) { dgSendTime.End(); dgSendInterval.Begin(); throughput.End(); throughput.Begin(); } sendBuffer[p.GetPacketSequenceNumber()] = p; Interlocked.Increment(ref unacknowledged); } statistics.incNumberOfSentDataPackets(); }
/** * receiver algorithm * see specification P11. */ public void ReceiverAlgorithm() { //check ACK timer long currentTime = Util.getCurrentTime(); if (nextACK < currentTime) { nextACK = currentTime + ackTimerInterval; ProcessACKEvent(true); } //check NAK timer if (nextNAK < currentTime) { nextNAK = currentTime + nakTimerInterval; ProcessNAKEvent(); } //check EXP timer if (nextEXP < currentTime) { nextEXP = currentTime + expTimerInterval; ProcessEXPEvent(); } //perform time-bounded UDP receive IUDTPacket packet = null; handoffQueue.TryTake(out packet, (int)Util.GetSYNTime()); if (packet != null) { //reset exp count to 1 expCount = 1; //If there is no unacknowledged data packet, or if this is an //ACK or NAK control packet, reset the EXP timer. bool needEXPReset = false; if (packet.IsControlPacket()) { ControlPacket cp = (ControlPacket)packet; int cpType = cp.GetControlPacketType(); if (cpType == (int)ControlPacketType.ACK || cpType == (int)ControlPacketType.NAK) { needEXPReset = true; } } if (needEXPReset) { nextEXP = Util.getCurrentTime() + expTimerInterval; } if (storeStatistics) { processTime.Begin(); } ProcessUDTPacket(packet); if (storeStatistics) { processTime.End(); } } Thread.Yield(); }