コード例 #1
0
        public static bool Correlate(ConnectionRequestDatagram o1, ConnectionConfirmedDatagram o2)
        {
            //Test ack
            if (o1.SourceTsap.Span.SequenceEqual(o2.SourceTsap.Span) && o1.DestTsap.Span.SequenceEqual(o2.DestTsap.Span))
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        public ConnectionConfirmedDatagram BuildCc(Rfc1006ProtocolContext context, ConnectionRequestDatagram req)
        {
            context.CalcLength(context, out byte li, out ushort length);
            context.SizeTpduSending = req.SizeTpduReceiving;
            var result = new ConnectionConfirmedDatagram
            {
                Li = li,
                SizeTpduReceiving = context.SizeTpduReceiving,
                SourceTsapLength  = req.DestTsapLength,
                SourceTsap        = req.SourceTsap,
                DestTsapLength    = req.DestTsapLength,
                DestTsap          = req.DestTsap
            };

            result.Tkpt.Length = length;
            return(result);
        }
コード例 #3
0
        public static ConnectionConfirmedDatagram TranslateFromMemory(Memory <byte> data, out int processed)
        {
            var span   = data.Span;
            var result = new ConnectionConfirmedDatagram
            {
                Tkpt = new TpktDatagram
                {
                    Sync1  = span[0],
                    Sync2  = span[1],
                    Length = BinaryPrimitives.ReadUInt16BigEndian(span.Slice(2, 2))
                },
                Li                = span[4],
                PduType           = span[5],
                DstRef            = BinaryPrimitives.ReadInt16BigEndian(span.Slice(6, 2)),
                SrcRef            = BinaryPrimitives.ReadInt16BigEndian(span.Slice(8, 2)),
                ClassOption       = span[10],
                ParmCodeTpduSize  = span[11],
                Unknown           = span[12],
                SizeTpduReceiving = span[13],
            };

            var offset = 14;

            result.ParmCodeSrcTsap  = span[offset++];
            result.SourceTsapLength = span[offset++];

            result.SourceTsap = data.Slice(offset, (int)result.SourceTsapLength);
            offset           += (int)result.SourceTsapLength;

            result.ParmCodeDestTsap = span[offset++];
            result.DestTsapLength   = span[offset++];
            result.SourceTsap       = data.Slice(offset, result.DestTsapLength);
            offset += (int)result.DestTsapLength;

            processed = offset;
            return(result);
        }
コード例 #4
0
        public static IMemoryOwner <byte> TranslateToMemory(ConnectionConfirmedDatagram datagram, out int memoryLength)
        {
            var length = memoryLength = datagram.Tkpt.Length;
            var result = MemoryPool <byte> .Shared.Rent(length);  // TODO: use MemorBUffer and return check if we could use ArrayBuffer

            var mem  = result.Memory;
            var span = mem.Span;

            span[0] = datagram.Tkpt.Sync1;
            span[1] = datagram.Tkpt.Sync2;
            BinaryPrimitives.WriteUInt16BigEndian(span.Slice(2, 2), datagram.Tkpt.Length);
            span[4] = datagram.Li;
            span[5] = datagram.PduType;
            BinaryPrimitives.WriteInt16BigEndian(span.Slice(6, 2), datagram.DstRef);
            BinaryPrimitives.WriteInt16BigEndian(span.Slice(8, 2), datagram.SrcRef);
            span[10] = datagram.ClassOption;
            span[11] = datagram.ParmCodeTpduSize;

            var offset = 11;

            span[offset++] = datagram.ParmCodeTpduSize;
            span[offset++] = datagram.SizeTpduReceivingLength;
            datagram.SizeTpduReceiving.CopyTo(mem.Slice(offset));
            offset += datagram.SizeTpduReceivingLength;

            span[offset++] = datagram.ParmCodeSrcTsap;
            span[offset++] = datagram.SourceTsapLength;
            datagram.SourceTsap.CopyTo(mem.Slice(offset));
            offset += datagram.SourceTsapLength;

            span[offset++] = datagram.ParmCodeDestTsap;
            span[offset++] = datagram.DestTsapLength;
            datagram.DestTsap.CopyTo(mem.Slice(offset));
            //offset += datagram.DestTsapLength;

            return(result);
        }
コード例 #5
0
 public static Memory <byte> TranslateToMemory(ConnectionConfirmedDatagram datagram)
 {
     return(new Memory <byte>());
 }
コード例 #6
0
        public static ConnectionConfirmedDatagram TranslateFromMemory(Memory <byte> data, out int processed)
        {
            var span   = data.Span;
            var result = new ConnectionConfirmedDatagram
            {
                Tkpt = new TpktDatagram
                {
                    Sync1  = span[0],
                    Sync2  = span[1],
                    Length = BinaryPrimitives.ReadUInt16BigEndian(span.Slice(2, 2))
                },
                Li          = span[4],
                PduType     = span[5],
                DstRef      = BinaryPrimitives.ReadInt16BigEndian(span.Slice(6, 2)),
                SrcRef      = BinaryPrimitives.ReadInt16BigEndian(span.Slice(8, 2)),
                ClassOption = span[10],
            };

            int offset;

            for (offset = 11; offset < data.Length;)
            {
                switch (span[offset])
                {
                case 0xc0:
                {
                    result.ParmCodeTpduSize        = span[offset++];
                    result.SizeTpduReceivingLength = span[offset++];
                    result._sizeTpduReceiving      = MemoryPool <byte> .Shared.Rent(result.SizeTpduReceivingLength);

                    data.Slice(offset, result.SizeTpduReceivingLength).CopyTo(result._sizeTpduReceiving.Memory);
                    result.SizeTpduReceiving = result._sizeTpduReceiving.Memory.Slice(0, result.SizeTpduReceivingLength);
                    offset += result.SizeTpduReceivingLength;
                }
                break;

                case 0xc1:
                {
                    result.ParmCodeSrcTsap  = span[offset++];
                    result.SourceTsapLength = span[offset++];
                    result._sourceTsap      = MemoryPool <byte> .Shared.Rent(result.SourceTsapLength);

                    data.Slice(offset, result.SourceTsapLength).CopyTo(result._sourceTsap.Memory);
                    result.SourceTsap = result._sourceTsap.Memory.Slice(0, result.SourceTsapLength);
                    offset           += result.SourceTsapLength;
                }
                break;

                case 0xc2:
                {
                    result.ParmCodeDestTsap = span[offset++];
                    result.DestTsapLength   = span[offset++];
                    result._destTsap        = MemoryPool <byte> .Shared.Rent(result.DestTsapLength);

                    data.Slice(offset, result.DestTsapLength).CopyTo(result._destTsap.Memory);
                    result.DestTsap = result._destTsap.Memory.Slice(0, result.DestTsapLength);
                    offset         += result.DestTsapLength;
                }
                break;

                default:
                    break;
                }
            }


            processed = offset;
            return(result);
        }