Beispiel #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);
            }
        }
Beispiel #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());
        }
Beispiel #3
0
        private static string TlvCollectionToString(TlvCollection tlvCollection, SmppEncodingService encodingService)
        {
            var tags = new StringBuilder();

            tags.Append("[");
            foreach (var tlv in tlvCollection)
            {
                tags.AppendFormat("{0}:{1} ", tlv.Tag, BytesToString(tlv.RawValue, encodingService));
            }
            tags.Append("]");

            return(tags.ToString());
        }
Beispiel #4
0
 protected override void Parse(ByteBuffer buffer)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     vSourceAddress = SmppAddress.Parse(buffer);
     vEsmeAddress   = SmppAddress.Parse(buffer);
     //If there are some bytes left,
     //construct a tlv collection
     if (buffer.Length > 0)
     {
         vTlv = TlvCollection.Parse(buffer);
     }
 }
Beispiel #5
0
 protected override void Parse(ByteBuffer buffer)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     vServiceType        = DecodeCString(buffer, vSmppEncodingService);
     vSourceAddress      = SmppAddress.Parse(buffer, vSmppEncodingService);
     vDestinationAddress = SmppAddress.Parse(buffer, vSmppEncodingService);
     vEsmClass           = (EsmClass)GetByte(buffer);
     vRegisteredDelivery = (RegisteredDelivery)GetByte(buffer);
     vDataCoding         = (DataCoding)GetByte(buffer);
     if (buffer.Length > 0)
     {
         vTlv = TlvCollection.Parse(buffer, vSmppEncodingService);
     }
 }
Beispiel #6
0
 protected override void Parse(ByteBuffer buffer)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     //We require at least 1 byte for this pdu
     if (buffer.Length < 1)
     {
         throw new NotEnoughBytesException("data_sm_resp requires at least 1 byte of body data");
     }
     _vMessageId = DecodeCString(buffer);
     if (buffer.Length > 0)
     {
         VTlv = TlvCollection.Parse(buffer);
     }
 }
Beispiel #7
0
 protected override void Parse(ByteBuffer buffer)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     //If Error code is not zero, buffer.Length may be zero
     //This may happen because the SMSC may not return the system_id field
     //if the origianl bind request contained an error.
     if (Header.ErrorCode != SmppErrorCode.EsmeRok && buffer.Length == 0)
     {
         _vSystemId = ""; return;
     }
     //Otherwise, there must be something in the buffer
     _vSystemId = DecodeCString(buffer);
     if (buffer.Length > 0)
     {
         VTlv = TlvCollection.Parse(buffer);
     }
 }
Beispiel #8
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);
        }
Beispiel #9
0
        protected override void Parse(ByteBuffer buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            VServiceType           = DecodeCString(buffer);
            VSourceAddress         = SmppAddress.Parse(buffer);
            VDestinationAddress    = SmppAddress.Parse(buffer);
            VEsmClass              = (EsmClass)GetByte(buffer);
            _vProtocolId           = GetByte(buffer);
            _vPriorityFlag         = (PriorityFlag)GetByte(buffer);
            _vScheduleDeliveryTime = DecodeCString(buffer);
            _vValidityPeriod       = DecodeCString(buffer);
            VRegisteredDelivery    = (RegisteredDelivery)GetByte(buffer);
            _vReplaceIfPresent     = GetByte(buffer) == 0 ? false : true;
            VDataCoding            = (DataCoding)GetByte(buffer);
            _vSmDefalutMessageId   = GetByte(buffer);
            int length = GetByte(buffer);

            if (length == 0)
            {
                _vMessageBytes = null;
            }
            else
            {
                if (length > buffer.Length)
                {
                    throw new NotEnoughBytesException("Pdu encoutered less bytes than indicated by message length");
                }
                _vMessageBytes = buffer.Remove(length);
            }
            if (buffer.Length > 0)
            {
                VTlv = TlvCollection.Parse(buffer);
            }
        }
Beispiel #10
0
 internal PDU(PDUHeader header)
 {
     vHeader = header;
     vTlv = new TlvCollection();
 }
Beispiel #11
0
 internal Pdu(PduHeader header)
 {
     VHeader = header;
     VTlv    = new TlvCollection();
 }
Beispiel #12
0
 /// <summary>
 /// Enables foreach functionality for this class
 /// </summary>
 /// <returns>The next item in the list</returns>
 public IEnumerator GetEnumerator()
 {
     return(TlvCollection.GetEnumerator());
 }
Beispiel #13
0
 internal PDU(PDUHeader header)
 {
     vHeader = header;
     vTlv    = new TlvCollection();
 }
Beispiel #14
0
 internal PDU(PDUHeader header, SmppEncodingService smppEncodingService)
 {
     vHeader = header;
     vSmppEncodingService = smppEncodingService;
     vTlv = new TlvCollection();
 }