Ejemplo n.º 1
0
        void IMaslConnectionObserver.OnMaslUserDataArrival(byte[] maslUserData)
        {
            try
            {
                var frame = SaiFrame.Parse(maslUserData);

                if (this.CheckFrame(frame))
                {
                    _seqNoManager.UpdateAckSeq(frame.SequenceNo);

                    _currentState.HandleFrame(frame);

                    if (this.SaiFrameReceived != null)
                    {
                        this.SaiFrameReceived(null, new SaiFrameIncomingEventArgs(frame));
                    }
                }
                else if (_seqNoManager.IsBeyondRange(frame.SequenceNo))
                {
                    throw new Exception(string.Format("检测到丢包,当前确认序号={0},收到的发送序号={1}。",
                                                      _seqNoManager.AckSeq, frame.SequenceNo));
                }
                else
                {
                    // 序号值为旧值,丢弃即可。
                }
            }
            catch (System.Exception ex)
            {
                LogUtility.Error(string.Format("Sai: {0} \r\n{1}", _rsspEndPoint.ID, ex));

                this.Disconnect(MaslErrorCode.NotDefined, 0);
            }
        }
Ejemplo n.º 2
0
        void IAleTunnelObserver.OnAleFrameArrival(AleTunnel theConnection, AleFrame theFrame)
        {
            try
            {
                lock (_stateInputEventSyncLock)
                {
                    if (CheckFrame(theFrame))
                    {
                        // D类服务时,序列号有效;A类服务时,序列号无效。
                        if (_rsspEndPoint.ServiceType == ServiceType.D &&
                            theFrame.FrameType == AleFrameType.DataTransmission)
                        {
                            _seqNoManager.UpdateAckSeq(theFrame.SequenceNo);
                        }

                        //
                        if (theFrame.FrameType == AleFrameType.ConnectionRequest)
                        {
                            LogUtility.Info(string.Format("{0}: Received a CR frame on tcp connection(LEP={1}, REP={2}).",
                                                          this.RsspEP.ID, theConnection.LocalEndPoint, theConnection.RemoteEndPoint));

                            theConnection.Observer = this;

                            _currentState.HandleConnectionRequestFrame(theConnection, theFrame);
                        }
                        else if (theFrame.FrameType == AleFrameType.ConnectionConfirm)
                        {
                            LogUtility.Info(string.Format("{0}: Received a CC frame on tcp connection(LEP={1}, REP={2})).",
                                                          this.RsspEP.ID, theConnection.LocalEndPoint, theConnection.RemoteEndPoint));

                            _currentState.HandleConnectionConfirmFrame(theConnection, theFrame);
                        }
                        else if (theFrame.FrameType == AleFrameType.Disconnect)
                        {
                            _currentState.HandleDiFrame(theConnection, theFrame);
                        }
                        else if (theFrame.FrameType == AleFrameType.DataTransmission)
                        {
                            _currentState.HandleDataTransmissionFrame(theConnection, theFrame);
                        }
                    }
                    else if (_seqNoManager.IsBeyondRange(theFrame.SequenceNo))
                    {
                        throw new Exception(string.Format("检测到丢包,当前确认序号={0},收到的发送序号={1},TCP ID = {2}",
                                                          _seqNoManager.AckSeq, theFrame.SequenceNo, theConnection.ID));
                    }
                }
            }
            catch (System.Exception ex)
            {
                LogUtility.Error(string.Format("ALE: {0} : {1}", _rsspEndPoint.ID, ex));
                theConnection.Disconnect();
            }
        }
Ejemplo n.º 3
0
        public void Test_IsBeyondRange()
        {
            uint initialValue = 0;
            uint maxValue     = 255;

            var mgr = new SeqNoManager(initialValue, maxValue, 6);

            mgr.UpdateAckSeq(252);
            var actual = mgr.IsBeyondRange(250);

            Assert.AreEqual(false, actual);

            actual = mgr.IsBeyondRange(251);
            Assert.AreEqual(false, actual);

            actual = mgr.IsBeyondRange(252);
            Assert.AreEqual(false, actual);

            actual = mgr.IsBeyondRange(253);
            Assert.AreEqual(false, actual);

            actual = mgr.IsBeyondRange(254);
            Assert.AreEqual(false, actual);

            actual = mgr.IsBeyondRange(255);
            Assert.AreEqual(false, actual);

            actual = mgr.IsBeyondRange(0);
            Assert.AreEqual(false, actual);

            actual = mgr.IsBeyondRange(1);
            Assert.AreEqual(false, actual);

            actual = mgr.IsBeyondRange(2);
            Assert.AreEqual(false, actual);

            actual = mgr.IsBeyondRange(3);
            Assert.AreEqual(true, actual);

            actual = mgr.IsBeyondRange(4);
            Assert.AreEqual(true, actual);

            actual = mgr.IsBeyondRange(5);
            Assert.AreEqual(true, actual);

            actual = mgr.IsBeyondRange(10);
            Assert.AreEqual(true, actual);
        }