Type-length-value
Encyclopedia
Within data communication protocols, optional information may be encoded as a type-length-value or TLV element inside of the protocol. TLV is also known as tag-length value.

The type and length fields are fixed in size (typically 1-4 bytes), and the value field is of variable size. These fields are used as follows:
Type: A binary code, often simply alphanumeric, which indicates the kind of field that this part of the message represents;
Length: The size of the value field (typically in bytes);
Value: Variable-sized series of bytes which contains data for this part of the message.

Some advantages of using a TLV representation:
  • TLV sequences are easily searched using generalized parsing functions;
  • New message elements which are received at an older node can be safely skipped and the rest of the message can be parsed. This is similar to the way that unknown XML
    XML
    Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

     tags can be safely skipped;
  • TLV elements can be placed in any order inside the message body;
  • TLV elements are typically used in a binary format which makes parsing faster and the data smaller;
  • It is easier to generate XML from TLV to make human inspection of the data possible.

Examples

Imagine a message to make a telephone call. In a first version of a system this might use two message elements, a "command" and a "phoneNumberToCall":
command_c/4/makeCall_c/phoneNumberToCall_c/8/"722-4246"

Here command_c, makeCall_c and phoneNumberToCall_c are integer constants and 4 and 8 are the lengths of the "value" fields, respectively.

Later (in version 2) a new field containing the calling number could be added:
command_c/4/makeCall_c/callingNumber_c/14/"1-613-715-9719"/phoneNumberToCall_c/8/"722-4246"

A version 1 system which received a message from a version 2 system would first read the command_c element and then read an element of type callingNumber_c. The version 1 system does not understand ;callingNumber_c

so the length field is read (i.e. 14) and the system skips forward 14 bytes to read

phoneNumberToCall_c

which it understands, and message parsing carries on.

An example of usage is the Link Layer Discovery Protocol
Link Layer Discovery Protocol
The Link Layer Discovery Protocol is a vendor-neutral Link Layer protocol in the Internet Protocol Suite used by network devices for advertising their identity, capabilities, and neighbors on a IEEE 802 local area network, principally wired Ethernet...

 which allows for the sending of organizational-specific information as a TLV element within LLDP packets. Another example is the RR protocol used in GSM cell phones, defined in 3GPP 04.18.

In the RR protocol, each message is defined as a sequence of information elements.

Many other protocols use TLVs, such as COPS
Common Open Policy Service
The Common Open Policy Service Protocol is part of the internet protocol suite as defined by the IETF's RFC 2748. COPS specifies a simple client/server model for supporting policy control over Quality of Service signaling protocols...

, IS-IS
IS-IS
Intermediate System To Intermediate System , is a routing protocol designed to move information efficiently within a computer network, a group of physically connected computers or similar devices....

, and RADIUS
RADIUS
Remote Authentication Dial In User Service is a networking protocol that provides centralized Authentication, Authorization, and Accounting management for computers to connect and use a network service...

.

Other ways of representing data

Core TCP/IP protocols (particularly IP
Internet Protocol
The Internet Protocol is the principal communications protocol used for relaying datagrams across an internetwork using the Internet Protocol Suite...

, TCP
Transmission Control Protocol
The Transmission Control Protocol is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol , and therefore the entire suite is commonly referred to as TCP/IP...

, and UDP
User Datagram Protocol
The User Datagram Protocol is one of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer applications can send messages, in this case referred to as datagrams, to other hosts on an Internet Protocol network without requiring...

) use predefined, static fields.

Common TCP/IP-based protocols such as HTTP
Hypertext Transfer Protocol
The Hypertext Transfer Protocol is a networking protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web....

, FTP
File Transfer Protocol
File Transfer Protocol is a standard network protocol used to transfer files from one host to another host over a TCP-based network, such as the Internet. FTP is built on a client-server architecture and utilizes separate control and data connections between the client and server...

, SMTP
Simple Mail Transfer Protocol
Simple Mail Transfer Protocol is an Internet standard for electronic mail transmission across Internet Protocol networks. SMTP was first defined by RFC 821 , and last updated by RFC 5321 which includes the extended SMTP additions, and is the protocol in widespread use today...

, POP3
Post Office Protocol
In computing, the Post Office Protocol is an application-layer Internet standard protocol used by local e-mail clients to retrieve e-mail from a remote server over a TCP/IP connection. POP and IMAP are the two most prevalent Internet standard protocols for e-mail retrieval. Virtually all modern...

, and SIP
Session Initiation Protocol
The Session Initiation Protocol is an IETF-defined signaling protocol widely used for controlling communication sessions such as voice and video calls over Internet Protocol . The protocol can be used for creating, modifying and terminating two-party or multiparty sessions...

 use text-based "Field: Value" pairs formatted according to RFC 2822.

ASN.1 specifies several TLV-based encoding rules (BER
Basic Encoding Rules
The Basic Encoding Rules is one of the encoding formats defined as part of the ASN.1 standard specified by the ITU in X.690.-Description:...

, DER
Distinguished Encoding Rules
Distinguished Encoding Rules , is a message transfer syntax specified by the ITU in X.690. The Distinguished Encoding Rules of ASN.1 is an International Standard drawn from the constraints placed on basic encoding rules encodings by X.509. DER encodings are valid BER encodings...

), as well as non-TLV based ones (PER
Packed Encoding Rules
Packed encoding rules are ASN.1 encoding rules for producing a compact transfer syntax for data structures described in ASN.1, defined in 1994....

, XER
XML Encoding Rules
XML Encoding Rules , defined in ITU-T standard X.693, are a set of ASN.1 encoding rules for producing an XML-based verbose textual transfer syntax for data structures described in ASN.1....

).

CSN.1
CSN.1
In telecommunications and computer networking, Concrete Syntax Notation One is a standard and flexible notation that describes data structures for representing, encoding, transmitting, and decoding data, specifically GPRS used for cell phones...

 describes encoding rules using non-TLV semantics.

More recently, XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 has been used to implement messaging between different nodes in a network. These messages are typically prefixed with line-based text commands, such as with BEEP
BEEP
In computer networking, BEEP is a framework for creating network application protocols. It includes an application protocol kernel for connection-oriented asynchronous interactions, and can be used both for binary and text messages within the context of a single application user identity.BEEP is...

.

See also

  • Common Open Policy Service
    Common Open Policy Service
    The Common Open Policy Service Protocol is part of the internet protocol suite as defined by the IETF's RFC 2748. COPS specifies a simple client/server model for supporting policy control over Quality of Service signaling protocols...

     (COPS)
  • IS-IS
    IS-IS
    Intermediate System To Intermediate System , is a routing protocol designed to move information efficiently within a computer network, a group of physically connected computers or similar devices....

  • KLV
    KLV
    KLV is a data encoding standard, often used to embed information in video feeds. Items are encoded into Key-Length-Value triplets, where key identifies the data, length specifies the data's length, and value is the data itself...

    , for a very similar key-length-value scheme
  • Link Layer Discovery Protocol
    Link Layer Discovery Protocol
    The Link Layer Discovery Protocol is a vendor-neutral Link Layer protocol in the Internet Protocol Suite used by network devices for advertising their identity, capabilities, and neighbors on a IEEE 802 local area network, principally wired Ethernet...

  • RADIUS
    RADIUS
    Remote Authentication Dial In User Service is a networking protocol that provides centralized Authentication, Authorization, and Accounting management for computers to connect and use a network service...

  • tlve, A common TLV parser
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK