Beispiel #1
0
        public void ReadData(AcnBinaryReader data, bool tcpTransport)
        {
            //Read Preamble
            if (!tcpTransport)
            {
                PreambleSize  = data.ReadOctet2();
                PostambleSize = data.ReadOctet2();
            }

            string packetId = data.ReadUtf8String(12);

            if (packetId != PacketId)
            {
                throw new InvalidPacketException("The packet ID is not a valid ACN packet Id");
            }

            if (tcpTransport)
            {
                BlockSize = data.ReadOctet4();
            }

            //Read PDU Header
            Length     = data.ReadOctet2();
            Flags      = (byte)((Length & 0xF000) >> 12);
            Length    &= 0xFFF;
            ProtocolId = data.ReadOctet4();

            //Read CID
            SenderId = new Guid(data.ReadBytes(16));
        }
Beispiel #2
0
 protected override void ReadData(AcnBinaryReader data)
 {
     SourceName     = data.ReadUtf8String(64);
     SequenceNumber = data.ReadOctet4();
     EndpointID     = data.ReadOctet2();
     data.BaseStream.Seek(1, SeekOrigin.Current);
 }
Beispiel #3
0
        public static AcnPacket ReadTcpPacket(AcnBinaryReader data)
        {
            AcnRootLayer rootLayer = new AcnRootLayer();

            rootLayer.ReadData(data, true);

            return(ReadPacket(rootLayer, data));;
        }
Beispiel #4
0
            /// <summary>
            /// Creates the specified root layer.
            /// </summary>
            /// <param name="rootLayer">The root layer.</param>
            /// <param name="reader">The reader.</param>
            /// <returns></returns>
            public AcnPacket Create(AcnRootLayer rootLayer, AcnBinaryReader reader)
            {
                AcnPacket packet = (AcnPacket)Activator.CreateInstance(typeof(TPacketType));

                packet.Root = rootLayer;
                packet.ReadData(reader);
                return(packet);
            }
Beispiel #5
0
 protected override void ReadData(AcnBinaryReader data)
 {
     LeaderId               = new Guid(data.ReadBytes(16));
     ChannelNumber          = data.ReadOctet2();
     MemberId               = data.ReadOctet2();
     ReliableSequenceNumber = data.ReadOctet4();
     RefuseCode             = (ReasonCodes)data.ReadByte();
 }
Beispiel #6
0
 protected override void ReadData(AcnBinaryReader data)
 {
     LeaderId               = new Guid(data.ReadBytes(16));
     ChannelNumber          = data.ReadOctet2();
     MemberId               = data.ReadOctet2();
     ReliableSequenceNumber = data.ReadOctet4();
     ReciprocalChannel      = data.ReadOctet2();
 }
 protected override void ReadData(AcnBinaryReader data)
 {
     SourceName        = data.ReadUtf8String(64);
     Priority          = data.ReadByte();
     SyncPacketAddress = data.ReadOctet2();
     SequenceNumber    = data.ReadByte();
     Options           = data.ReadByte();
     Universe          = data.ReadOctet2();
 }
Beispiel #8
0
        public void ProcessPacket(IPEndPoint source, AcnRootLayer header, AcnBinaryReader data)
        {
            StreamingAcnDmxPacket newPacket = AcnPacket.ReadPacket(header, data) as StreamingAcnDmxPacket;

            if (newPacket != null)
            {
                RaiseNewPacket(source, newPacket);
            }
        }
Beispiel #9
0
            /// <summary>
            /// Reads the PDU information from the recieved packet data.
            /// </summary>
            /// <param name="data">The recieved packet data.</param>
            protected override void ReadData(AcnBinaryReader data)
            {
                Page       = data.ReadByte();
                TotalPages = data.ReadByte();

                for (int n = 2; n < Length; n += 2)
                {
                    Universes.Add(data.ReadOctet2());
                }
            }
Beispiel #10
0
        protected override void ReadData(AcnBinaryReader data)
        {
            AddressType          = data.ReadByte();
            FirstPropertyAddress = data.ReadOctet2();
            AddressIncrement     = data.ReadOctet2();

            int propertyLength = data.ReadOctet2();

            PropertyData = data.ReadBytes(propertyLength);
        }
Beispiel #11
0
 protected override void ReadData(AcnBinaryReader data)
 {
     ChannelNumber          = data.ReadOctet2();
     TotalSequenceNumber    = data.ReadOctet4();
     ReliableSequenceNumber = data.ReadOctet4();
     OldestAvailableWrapper = data.ReadOctet4();
     FirstMemberToAck       = data.ReadOctet2();
     LastMemberToAck        = data.ReadOctet2();
     MAKThreshold           = data.ReadOctet2();
     throw new NotImplementedException();
 }
Beispiel #12
0
        public static AcnPacket Build(AcnRootLayer header, AcnBinaryReader data)
        {
            IPacketBuilder packetType;

            if (factory.TryGetBuilder(new PacketKey(header.ProtocolId), out packetType))
            {
                AcnPacket packet = packetType.Create(header, data);
                return(packet);
            }

            return(null);
        }
Beispiel #13
0
 protected override void ReadData(AcnBinaryReader data)
 {
     ComponentId            = new Guid(data.ReadBytes(16));
     MemberId               = data.ReadOctet2();
     ChannelNumber          = data.ReadOctet2();
     ReciprocalChannel      = data.ReadOctet2();
     TotalSequenceNumber    = data.ReadOctet4();
     ReliableSequenceNumber = data.ReadOctet4();
     DestinationAddress     = SdtAddress.ReadData(data);
     ChannelParameterBlock  = ChannelParameterBlock.ReadData(data);
     AdHocExpiry            = data.ReadByte();
 }
Beispiel #14
0
        public static AcnPacket ReadPacket(AcnRootLayer header, AcnBinaryReader data)
        {
            AcnPacket packet = AcnPacket.Create(header);

            if (packet != null)
            {
                packet.Root = header;
                packet.ReadData(data);
            }

            return(packet);
        }
Beispiel #15
0
        private void ProcessAcnPacket(IPEndPoint source, AcnBinaryReader data)
        {
            AcnRootLayer rootLayer = GetRootLayer();

            rootLayer.ReadData(data, TcpTraffic);

            IProtocolFilter filter;

            if (filters.TryGetValue(rootLayer.ProtocolId, out filter))
            {
                filter.ProcessPacket(source, rootLayer, data);
            }
        }
Beispiel #16
0
        private void OnRecieve(IAsyncResult state)
        {
            if (PortOpen)
            {
                Tuple <Socket, MemoryStream> recieveState = (Tuple <Socket, MemoryStream>)(state.AsyncState);

                try
                {
                    if (recieveState != null)
                    {
                        EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                        int      dataSize       = recieveState.Item1.EndReceiveFrom(state, ref remoteEndPoint);

                        //Protect against UDP loopback where we recieve our own packets.
                        //Ensure we have actually recieved data.
                        if (LocalEndPoint != remoteEndPoint && dataSize > 0)
                        {
                            LastPacket = DateTime.Now;

                            IPEndPoint ipEndPoint = (IPEndPoint)remoteEndPoint;

                            //If this is a TCP connection then the returned enpoint will be empty and we must use the connection endpoint.
                            if (ipEndPoint.Port == 0)
                            {
                                ipEndPoint = (IPEndPoint)recieveState.Item1.RemoteEndPoint;
                            }

                            AcnBinaryReader packetReader = new AcnBinaryReader(recieveState.Item2);
                            ProcessAcnPacket(ipEndPoint, packetReader);
                        }
                    }
                }
                catch (SocketException)
                {
                    Close();
                }
                catch (Exception ex)
                {
                    RaiseUnhandledException(ex);
                }
                finally
                {
                    //Attempt to recieve another packet.
                    if (PortOpen)
                    {
                        StartRecieve(recieveState.Item1, recieveState.Item2);
                    }
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// Processes the packet that have been recieved and allocated to this filter.
        /// </summary>
        /// <param name="source">The source IP address of the packet.</param>
        /// <param name="header">The header information for the ACN packet.</param>
        /// <param name="data">The data reader for the remaining packet data.</param>
        /// <remarks>
        /// Only packets that have supported protocol ID's will be sent to this function.
        /// </remarks>
        void IProtocolFilter.ProcessPacket(IPEndPoint source, AcnRootLayer header, AcnBinaryReader data)
        {
            RdmNetPacket newPacket = AcnPacket.ReadPacket(header, data) as RdmNetPacket;

            if (newPacket != null)
            {
                RdmBinaryReader dmxReader = new RdmBinaryReader(new MemoryStream(newPacket.RdmNet.RdmData));

                //Skip Start Code and sub-start code
                dmxReader.BaseStream.Seek(1, SeekOrigin.Begin);

                RdmPacket rdmPacket = RdmPacket.ReadPacket(dmxReader);
                RaiseNewRdmPacket(new RdmEndPoint(source, newPacket.Framing.EndpointID), rdmPacket);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Processes the packet that have been recieved and allocated to this filter.
        /// </summary>
        /// <param name="source">The source IP address of the packet.</param>
        /// <param name="header">The header information for the ACN packet.</param>
        /// <param name="data">The data reader for the remaining packet data.</param>
        /// <remarks>
        /// Only packets that have supported protocol ID's will be sent to this function.
        /// </remarks>
        public void ProcessPacket(IPEndPoint source, AcnRootLayer header, AcnBinaryReader data)
        {
            AcnPacket packet = AcnPacket.ReadPacket(header, data);

            if (packet is StreamingAcnDmxPacket)
            {
                RaiseNewPacket(source, (StreamingAcnDmxPacket)packet);
            }
            if (packet is StreamingAcnSynchronizationPacket)
            {
                RaiseNewSynchronize(source, (StreamingAcnSynchronizationPacket)packet);
            }
            if (packet is StreamingAcnDiscoveryPacket)
            {
                RaiseNewDiscovery(source, (StreamingAcnDiscoveryPacket)packet);
            }
        }
Beispiel #19
0
        public static SdtAddress ReadData(AcnBinaryReader data)
        {
            switch ((SdtAddressTypes)data.ReadByte())
            {
            case SdtAddressTypes.Null:
                return(new NullAddress());

            case SdtAddressTypes.IPv4:
                return(new IPv4Address());

            case SdtAddressTypes.IPv6:
                return(new IPv6Address());

            default:
                throw new InvalidOperationException("Unknown address STD type.");
            }
        }
Beispiel #20
0
        /// <summary>
        /// Creates the specified root layer.
        /// </summary>
        /// <param name="rootLayer">The root layer.</param>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public AcnPacket Create(AcnRootLayer rootLayer, AcnBinaryReader reader)
        {
            long startPosition = reader.BaseStream.Position;

            PduHeader pduHeader = new PduHeader();

            pduHeader.ReadPdu(reader);

            IPacketBuilder builder;

            if (TryGetBuilder(new PacketKey(pduHeader.Vector), out builder))
            {
                reader.BaseStream.Seek(startPosition, System.IO.SeekOrigin.Begin);
                return(builder.Create(rootLayer, reader));
            }

            return(null);
        }
Beispiel #21
0
        public virtual void ReadPdu(AcnBinaryReader data)
        {
            //Read PDU Header
            Length  = data.ReadOctet2();
            Flags   = (PduFlags)((Length & 0xF000) >> 12);
            Length &= 0xFFF;

            switch (vectorLength)
            {
            case 1:
                Vector = data.ReadByte();
                break;

            case 4:
                Vector = data.ReadOctet4();
                break;
            }

            ReadData(data);
        }
Beispiel #22
0
 protected abstract void ReadData(AcnBinaryReader data);
Beispiel #23
0
 protected override void ReadData(AcnBinaryReader data)
 {
     base.ReadData(data);
 }
Beispiel #24
0
 void IProtocolFilter.ProcessPacket(IPEndPoint source, AcnRootLayer header, AcnBinaryReader data)
 {
     parent.LastContact = DateTime.Now;
 }
Beispiel #25
0
 protected override void ReadData(AcnBinaryReader data)
 {
     ProtocolId = data.ReadOctet4();
 }
 protected override void ReadData(AcnBinaryReader data)
 {
     Framing.ReadPdu(data);
 }
Beispiel #27
0
 protected override void ReadData(AcnBinaryReader data)
 {
     RdmData = data.ReadBytes(Length - 3);
 }
Beispiel #28
0
 /// <summary>
 /// Reads the PDU information from the recieved packet data.
 /// </summary>
 /// <param name="data">The recieved packet data.</param>
 protected override void ReadData(AcnBinaryReader data)
 {
     SourceName = data.ReadUtf8String(64);
     data.BaseStream.Seek(4, SeekOrigin.Current);
 }
Beispiel #29
0
 protected override void ReadData(AcnBinaryReader data)
 {
     AddressType = data.ReadByte();
 }
Beispiel #30
0
 protected override void ReadData(AcnBinaryReader data)
 {
     ProtocolId = data.ReadOctet4();
     Reason     = (ReasonCodes)data.ReadByte();
 }