Пример #1
0
 /// <summary>
 /// receive a packet from server from the peer
 /// 从对等服务器接收数据包
 /// </summary>
 /// <param name="p"></param>
 public void receive(UDTPacket p)
 {
     try
     {
         if (p is Acknowledgement)
         {
             Acknowledgement acknowledgement = (Acknowledgement)p;
             onAcknowledge(acknowledgement);
         }
         else if (p is NegativeAcknowledgement)
         {
             NegativeAcknowledgement nak = (NegativeAcknowledgement)p;
             onNAKPacketReceived(nak);
         }
         else if (p is KeepAlive)
         {
             session.getSocket().getReceiver().resetEXPCount();
         }
         else if (p is DataPacket)
         {
             ////返回的确认数据包
             ////DataPacketAnswer Answer = (DataPacketAnswer)p;
             //if (largestSentSequenceNumber == (int)p.getPacketSequenceNumber())
             //{
             //    sendQueueStart.CountDown();
             //}
         }
     }
     catch (Exception ex)
     {
         Log.Write(this.ToString(), ex);
     }
 }
Пример #2
0
        protected void SendNAK(List <long> sequenceNumbers)
        {
            if (sequenceNumbers.Count == 0)
            {
                return;
            }
            NegativeAcknowledgement nAckPacket = new NegativeAcknowledgement();

            nAckPacket.AddLossInfo(sequenceNumbers);
            nAckPacket.SetSession(session);
            nAckPacket.DestinationID = session.Destination.SocketID;
            endpoint.DoSend(nAckPacket);
            statistics.incNumberOfNAKSent();
        }
Пример #3
0
        /**
         * procedure when a NAK is received (spec. p 14)
         * @param nak
         */
        protected void OnNAKPacketReceived(NegativeAcknowledgement nak)
        {
            foreach (int i in nak.GetDecodedLossInfo())
            {
                senderLossList.Insert(i);
            }
            session.CongestionControl.OnLoss(nak.GetDecodedLossInfo());
            session.Socket.GetReceiver().ResetEXPTimer();
            statistics.incNumberOfNAKReceived();

            //if(logger.isLoggable(Level.FINER)){
            //	logger.finer("NAK for "+nak.getDecodedLossInfo().size()+" packets lost, "
            //			+"set send period to "+session.getCongestionControl().getSendInterval());
            //}
            return;
        }
Пример #4
0
 //receive a packet from server from the peer
 internal void Receive(IUDTPacket p)
 {
     if (p is Acknowledgement)
     {
         Acknowledgement acknowledgement = (Acknowledgement)p;
         OnAcknowledge(acknowledgement);
     }
     else if (p is NegativeAcknowledgement)
     {
         NegativeAcknowledgement nak = (NegativeAcknowledgement)p;
         OnNAKPacketReceived(nak);
     }
     else if (p is KeepAlive)
     {
         session.Socket.GetReceiver().ResetEXPCount();
     }
 }
Пример #5
0
        /**
         * write a NAK triggered by a received sequence number that is larger than
         * the largestReceivedSeqNumber + 1
         * @param currentSequenceNumber - the currently received sequence number
         * @throws IOException
         */
        protected void SendNAK(long currentSequenceNumber)
        {
            NegativeAcknowledgement nAckPacket = new NegativeAcknowledgement();

            nAckPacket.AddLossInfo(largestReceivedSeqNumber + 1, currentSequenceNumber);
            nAckPacket.SetSession(session);
            nAckPacket.DestinationID = session.Destination.SocketID;
            //put all the sequence numbers between (but excluding) these two values into the
            //receiver loss list
            for (long i = largestReceivedSeqNumber + 1; i < currentSequenceNumber; i++)
            {
                ReceiverLossListEntry detectedLossSeqNumber = new ReceiverLossListEntry(i);
                receiverLossList.Insert(detectedLossSeqNumber);
            }
            endpoint.DoSend(nAckPacket);
            //logger.info("NAK for "+currentSequenceNumber);
            statistics.incNumberOfNAKSent();
        }
Пример #6
0
 protected void sendNAK(List <long> sequenceNumbers)
 {
     try
     {
         if (sequenceNumbers.Count == 0)
         {
             return;
         }
         NegativeAcknowledgement nAckPacket = new NegativeAcknowledgement();
         nAckPacket.addLossInfo(sequenceNumbers);
         nAckPacket.setSession(session);
         nAckPacket.setDestinationID(session.getDestination().getSocketID());
         endpoint.doSend(nAckPacket);
         statistics.incNumberOfNAKSent();
     }
     catch (Exception exc)
     {
         Log.Write(this.ToString(), exc);
     }
 }
Пример #7
0
        /// <summary>
        /// procedure when a NAK is received (spec. p 14)
        /// </summary>
        /// <param name="nak"></param>
        protected void onNAKPacketReceived(NegativeAcknowledgement nak)
        {
            try
            {
                foreach (int i in nak.getDecodedLossInfo())
                {
                    senderLossList.insert((long)i);
                }
                session.getCongestionControl().onLoss(nak.getDecodedLossInfo());
                session.getSocket().getReceiver().resetEXPTimer();
                statistics.incNumberOfNAKReceived();

                Log.Write(this.ToString(), "NAK for " + nak.getDecodedLossInfo().Count + " packets lost, "
                          + "set send period to " + session.getCongestionControl().getSendInterval());
            }
            catch (Exception ex)
            {
                Log.Write(this.ToString(), ex);
            }
        }
Пример #8
0
 /**
  * write a NAK triggered by a received sequence number that is larger than
  * the largestReceivedSeqNumber + 1
  * @param currentSequenceNumber - the currently received sequence number
  * @throws IOException
  */
 protected void sendNAK(long currentSequenceNumber)
 {
     try
     {
         NegativeAcknowledgement nAckPacket = new NegativeAcknowledgement();
         nAckPacket.addLossInfo(largestReceivedSeqNumber + 1, currentSequenceNumber);
         nAckPacket.setSession(session);
         nAckPacket.setDestinationID(session.getDestination().getSocketID());
         //put all the sequence numbers between (but excluding) these two values into the
         //receiver loss list
         for (long i = largestReceivedSeqNumber + 1; i < currentSequenceNumber; i++)
         {
             ReceiverLossListEntry detectedLossSeqNumber = new ReceiverLossListEntry(i);
             receiverLossList.insert(detectedLossSeqNumber);
         }
         endpoint.doSend(nAckPacket);
         //logger.info("NAK for "+currentSequenceNumber);
         statistics.incNumberOfNAKSent();
     }
     catch (Exception exc)
     {
         Log.Write(this.ToString(), exc);
     }
 }
Пример #9
0
        public static int DeleteAuthenticationKey(bool targetSpecificSuId, bool deleteAllKeys, int wacnId, int systemId, int unitId)
        {
            Output.DebugLine("DeleteAuthenticationKey() :: targetSpecificSuId: {0}, deleteAllKeys: {1}, wacnId: 0x{2:X}, systemId: 0x{3:X}, unitId: 0x{4:X}", targetSpecificSuId, deleteAllKeys, wacnId, systemId, unitId);

            SuId commandSuId = new SuId(wacnId, systemId, unitId);

            Output.DebugLine("command suid - {0}", commandSuId.ToString());

            DeleteAuthenticationKeyCommand commandKmmBody = new DeleteAuthenticationKeyCommand(targetSpecificSuId, deleteAllKeys, commandSuId);

            Output.DebugLine("command kmm body - {0}", commandKmmBody.ToString());

            KmmFrame commandKmmFrame = new KmmFrame(commandKmmBody);

            Output.DebugLine("command kmm frame - {0}", commandKmmFrame.ToString());
            byte[] toRadio = commandKmmFrame.ToBytes();

            byte[] fromRadio;

            try
            {
                fromRadio = Network.QueryRadio(toRadio);
            }
            catch (Exception ex)
            {
                Output.ErrorLine("unable to connect to radio: {0}", ex.Message);
                return(-1);
            }

            KmmFrame responseKmmFrame = new KmmFrame(fromRadio);

            Output.DebugLine("response kmm frame - {0}", responseKmmFrame.ToString());

            KmmBody responseKmmBody = responseKmmFrame.KmmBody;

            if (responseKmmBody is DeleteAuthenticationKeyResponse)
            {
                Output.DebugLine("received DeleteAuthenticationKeyResponse kmm");
                DeleteAuthenticationKeyResponse deleteAuthenticationKeyResponse = responseKmmBody as DeleteAuthenticationKeyResponse;
                Output.DebugLine("response kmm body - {0}", deleteAuthenticationKeyResponse.ToString());
                Output.DebugLine("response suid - {0}", deleteAuthenticationKeyResponse.SuId.ToString());

                if (deleteAuthenticationKeyResponse.Status == Status.CommandWasPerformed)
                {
                    return(0);
                }
                else
                {
                    Output.ErrorLine("abnormal response - status: {0} (0x{1:X2})", deleteAuthenticationKeyResponse.Status.ToString(), (byte)deleteAuthenticationKeyResponse.Status);
                    return(-1);
                }
            }
            else if (responseKmmBody is NegativeAcknowledgement)
            {
                Output.ErrorLine("received NegativeAcknowledgement kmm");
                NegativeAcknowledgement negativeAcknowledgement = responseKmmBody as NegativeAcknowledgement;
                Output.DebugLine("response kmm body - {0}", negativeAcknowledgement.ToString());
                return(-1);
            }
            else
            {
                Output.ErrorLine("received unexpected kmm");
                return(-1);
            }
        }
Пример #10
0
        public static int ListSuIdItems()
        {
            Output.DebugLine("ListSuIdItems()");

            bool needsAnotherRun = true;
            int  inventoryMarker = 0;

            while (needsAnotherRun)
            {
                InventoryCommandListSuIdItems commandKmmBody = new InventoryCommandListSuIdItems(inventoryMarker, 59);
                Output.DebugLine("command kmm body - {0}", commandKmmBody.ToString());

                KmmFrame commandKmmFrame = new KmmFrame(commandKmmBody);
                Output.DebugLine("command kmm frame - {0}", commandKmmFrame.ToString());
                byte[] toRadio = commandKmmFrame.ToBytes();

                byte[] fromRadio;

                try
                {
                    fromRadio = Network.QueryRadio(toRadio);
                }
                catch (Exception ex)
                {
                    Output.ErrorLine("unable to connect to radio: {0}", ex.Message);
                    return(-1);
                }

                KmmFrame responseKmmFrame = new KmmFrame(fromRadio);
                Output.DebugLine("response kmm frame - {0}", responseKmmFrame.ToString());

                KmmBody responseKmmBody = responseKmmFrame.KmmBody;

                if (responseKmmBody is InventoryResponseListSuIdItems)
                {
                    Output.DebugLine("received InventoryResponseListSuIdItems kmm");
                    InventoryResponseListSuIdItems inventoryResponseListSuIdItems = responseKmmBody as InventoryResponseListSuIdItems;
                    Output.DebugLine("response kmm body - {0}", inventoryResponseListSuIdItems.ToString());

                    inventoryMarker = inventoryResponseListSuIdItems.InventoryMarker;
                    Output.DebugLine("inventory marker - {0}", inventoryMarker);

                    if (inventoryMarker > 0)
                    {
                        needsAnotherRun = true;
                    }
                    else
                    {
                        needsAnotherRun = false;
                    }

                    foreach (SuIdStatus responseSuIdStatus in inventoryResponseListSuIdItems.SuIdStatuses)
                    {
                        Output.InfoLine("WACN: 0x{0:X}, System: 0x{1:X}, Unit: 0x{2:X}, Key Assigned: {3}, Is Active: {4}", responseSuIdStatus.SuId.WacnId, responseSuIdStatus.SuId.SystemId, responseSuIdStatus.SuId.UnitId, responseSuIdStatus.KeyAssigned, responseSuIdStatus.ActiveSuId);
                    }
                }
                else if (responseKmmBody is NegativeAcknowledgement)
                {
                    Output.ErrorLine("received NegativeAcknowledgement kmm");
                    NegativeAcknowledgement negativeAcknowledgement = responseKmmBody as NegativeAcknowledgement;
                    Output.DebugLine("response kmm body - {0}", negativeAcknowledgement.ToString());
                    return(-1);
                }
                else
                {
                    Output.ErrorLine("received unexpected kmm");
                    return(-1);
                }
            }

            return(0);
        }
Пример #11
0
        public static int ListActiveSuId()
        {
            Output.DebugLine("ListActiveSuId()");

            InventoryCommandListActiveSuId commandKmmBody = new InventoryCommandListActiveSuId();

            Output.DebugLine("command kmm body - {0}", commandKmmBody.ToString());

            KmmFrame commandKmmFrame = new KmmFrame(commandKmmBody);

            Output.DebugLine("command kmm frame - {0}", commandKmmFrame.ToString());
            byte[] toRadio = commandKmmFrame.ToBytes();

            byte[] fromRadio;

            try
            {
                fromRadio = Network.QueryRadio(toRadio);
            }
            catch (Exception ex)
            {
                Output.ErrorLine("unable to connect to radio: {0}", ex.Message);
                return(-1);
            }

            KmmFrame responseKmmFrame = new KmmFrame(fromRadio);

            Output.DebugLine("response kmm frame - {0}", responseKmmFrame.ToString());

            KmmBody responseKmmBody = responseKmmFrame.KmmBody;

            if (responseKmmBody is InventoryResponseListActiveSuId)
            {
                Output.DebugLine("received InventoryResponseListActiveSuId kmm");
                InventoryResponseListActiveSuId inventoryResponseListActiveSuId = responseKmmBody as InventoryResponseListActiveSuId;
                Output.DebugLine("response kmm body - {0}", inventoryResponseListActiveSuId.ToString());
                Output.DebugLine("response suid - {0}", inventoryResponseListActiveSuId.SuId.ToString());

                if (inventoryResponseListActiveSuId.Status == Status.CommandWasPerformed)
                {
                    Output.InfoLine("WACN: 0x{0:X}, System: 0x{1:X}, Unit: 0x{2:X}, Key Assigned: {3}, Is Active: {4}", inventoryResponseListActiveSuId.SuId.WacnId, inventoryResponseListActiveSuId.SuId.SystemId, inventoryResponseListActiveSuId.SuId.UnitId, inventoryResponseListActiveSuId.KeyAssigned, inventoryResponseListActiveSuId.ActiveSuId);
                    return(0);
                }
                else
                {
                    Output.ErrorLine("abnormal response - status: {0} (0x{1:X2})", inventoryResponseListActiveSuId.Status.ToString(), (byte)inventoryResponseListActiveSuId.Status);
                    return(-1);
                }
            }
            else if (responseKmmBody is NegativeAcknowledgement)
            {
                Output.ErrorLine("received NegativeAcknowledgement kmm");
                NegativeAcknowledgement negativeAcknowledgement = responseKmmBody as NegativeAcknowledgement;
                Output.DebugLine("response kmm body - {0}", negativeAcknowledgement.ToString());
                return(-1);
            }
            else
            {
                Output.ErrorLine("received unexpected kmm");
                return(-1);
            }
        }
Пример #12
0
        public static int LoadAuthenticationKey(bool targetSpecificSuId, int wacnId, int systemId, int unitId, byte[] key)
        {
            Output.DebugLine("LoadAuthenticationKey() :: targetSpecificSuId: {0}, wacnId: 0x{1:X}, systemId: 0x{2:X}, unitId: 0x{3:X}, key (hex): {4}", targetSpecificSuId, wacnId, systemId, unitId, BitConverter.ToString(key));

            SuId commandSuId = new SuId(wacnId, systemId, unitId);

            Output.DebugLine("command suid - {0}", commandSuId.ToString());

            LoadAuthenticationKeyCommand commandKmmBody = new LoadAuthenticationKeyCommand(targetSpecificSuId, commandSuId, key);

            Output.DebugLine("command kmm body - {0}", commandKmmBody.ToString());

            KmmFrame commandKmmFrame = new KmmFrame(commandKmmBody);

            Output.DebugLine("command kmm frame - {0}", commandKmmFrame.ToString());
            byte[] toRadio = commandKmmFrame.ToBytes();

            byte[] fromRadio;

            try
            {
                fromRadio = Network.QueryRadio(toRadio);
            }
            catch (Exception ex)
            {
                Output.ErrorLine("unable to connect to radio: {0}", ex.Message);
                return(-1);
            }

            KmmFrame responseKmmFrame = new KmmFrame(fromRadio);

            Output.DebugLine("response kmm frame - {0}", responseKmmFrame.ToString());

            KmmBody responseKmmBody = responseKmmFrame.KmmBody;

            if (responseKmmBody is LoadAuthenticationKeyResponse)
            {
                Output.DebugLine("received LoadAuthenticationKeyResponse kmm");
                LoadAuthenticationKeyResponse loadAuthenticationKeyResponse = responseKmmBody as LoadAuthenticationKeyResponse;
                Output.DebugLine("response kmm body - {0}", loadAuthenticationKeyResponse.ToString());
                Output.DebugLine("response suid - {0}", loadAuthenticationKeyResponse.SuId.ToString());

                if (loadAuthenticationKeyResponse.AssignmentSuccess == true && loadAuthenticationKeyResponse.Status == Status.CommandWasPerformed)
                {
                    return(0);
                }
                else
                {
                    Output.ErrorLine("abnormal response - assignment success: {0}, status: {1} (0x{2:X2})", loadAuthenticationKeyResponse.AssignmentSuccess, loadAuthenticationKeyResponse.Status.ToString(), (byte)loadAuthenticationKeyResponse.Status);
                    return(-1);
                }
            }
            else if (responseKmmBody is NegativeAcknowledgement)
            {
                Output.ErrorLine("received NegativeAcknowledgement kmm");
                NegativeAcknowledgement negativeAcknowledgement = responseKmmBody as NegativeAcknowledgement;
                Output.DebugLine("response kmm body - {0}", negativeAcknowledgement.ToString());
                return(-1);
            }
            else
            {
                Output.ErrorLine("received unexpected kmm");
                return(-1);
            }
        }