示例#1
0
        /// <summary>
        /// Parse byte[] into TLVs
        /// </summary>
        public void ParseByteArrayIntoTlvs(byte[] bytes, int offset)
        {
            int position = 0;

            TlvCollection.Clear();

            while (position < bytes.Length)
            {
                // The payload type
                var byteArraySegment = new ByteArraySegment(bytes, offset + position, TLVTypeLength.TypeLengthLength);
                var typeLength       = new TLVTypeLength(byteArraySegment);

                // create a TLV based on the type and
                // add it to the collection
                TLV currentTlv = TLVFactory(bytes, offset + position, typeLength.Type);
                if (currentTlv == null)
                {
                    break;
                }

                TlvCollection.Add(currentTlv);

                // stop at the first end tlv we run into
                if (currentTlv is EndOfLLDPDU)
                {
                    break;
                }

                // Increment the position to seek the next TLV
                position += (currentTlv.TotalLength);
            }
        }
示例#2
0
#pragma warning restore 0169, 0649
#endif

        #endregion


        #region Constructors

        /// <summary>
        /// Create an empty LLDPPacket
        /// </summary>
        public LLDPPacket()
        {
            Log.Debug("");

            // all lldp packets end with an EndOfLLDPDU tlv so add one
            // by default
            TlvCollection.Add(new EndOfLLDPDU());
        }
示例#3
0
        /// <summary>
        /// Create an empty LldpPacket
        /// </summary>
        public LldpPacket()
        {
            Log.Debug("");

            // all lldp packets end with an EndOfLldpdu TLV so add one
            // by default
            TlvCollection.Add(new EndOfLldpduTlv());
        }
示例#4
0
 /// <summary>
 /// Sets the given TLV(as a byte array)into the table.  This will not take
 /// care of big-endian/little-endian issues, although it will reverse the byte order
 /// in the tag for you(necessary for encoding).
 /// If the value is null, the parameter TLV will be removed instead.
 /// </summary>
 /// <param name="tag">The tag for this TLV.</param>
 /// <param name="val">The value of this TLV.</param>
 public void SetOptionalParamBytes(Tag tag, byte[] val)
 {
     if (val == null)
     {
         this.RemoveOptionalParameter(tag);
     }
     else
     {
         vTlv.Add(new Tlv.Tlv(tag, (ushort)val.Length, val));
     }
 }
示例#5
0
        /// <summary>
        /// Parse byte[] into TLVs
        /// </summary>
        public void ParseByteArrayIntoTlvs(byte[] bytes, int offset)
        {
            log.DebugFormat("bytes.Length {0}, offset {1}", bytes.Length, offset);

            int position = 0;

            TlvCollection.Clear();

            while (position < bytes.Length)
            {
                // The payload type
                var byteArraySegment = new ByteArraySegment(bytes, offset + position, TLVTypeLength.TypeLengthLength);
                var typeLength       = new TLVTypeLength(byteArraySegment);

                // create a TLV based on the type and
                // add it to the collection
                TLV currentTlv = TLVFactory(bytes, offset + position, typeLength.Type);
                if (currentTlv == null)
                {
                    log.Debug("currentTlv == null");
                    break;
                }

                log.DebugFormat("Adding tlv {0}, Type {1}",
                                currentTlv.GetType(), currentTlv.Type);
                TlvCollection.Add(currentTlv);

                // stop at the first end tlv we run into
                if (currentTlv is EndOfLLDPDU)
                {
                    break;
                }

                // Increment the position to seek the next TLV
                position += (currentTlv.TotalLength);
            }

            log.DebugFormat("Done, position {0}", position);
        }