blob: 1bf28c4cb795a914a33b18cfcfb7d5f9fe044689 [file] [log] [blame]
Alexander Afanasyeveee8c252013-11-21 23:22:41 +00001Type-Length-Value (TLV) Encoding
2--------------------------------
3
4Each NDN packet is encoded in a Type-Length-Value (TLV) format. NDN Interest and Data packets are distinguished by the type value in the first and outmost TLV\ :sub:`0`\ .
5
6An NDN packet is mainly a collection of TLVs inside TLV\ :sub:`0`\ . Some TLVs may contain sub-TLVs, and each sub-TLV may also be further nested. A guiding design principle is to keep the order of TLV\ :sub:`i`\ s deterministic, and keep the level of nesting as small as possible to minimize both processing overhead and chances for errors.
7
8Note that NDN packet format does not have a fixed packet header nor does it encode a protocol version number. Instead the design uses the TLV format to provide the flexibility of adding new types and phasing out old types as the protocol evolves over time. The absence of a fixed header makes it possible to support packets of very small sizes efficiently, without the header overhead.
9There is also no packet fragmentation support at network level.
10Whenever needed, NDN packets may be fragmented and reassembled hop-by-hop. [#f1]_
11
12.. [#f1] Today's IP networks provide point-to-point packet delivery and perform end-to-end fragmentation. An NDN network, on the other hand, may fetch requested data from any in-network storage, thus the notion of data flowing along an end-to-end path does not apply.
13
14Variable Size Encoding for type (T) and length (L)
15~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16
17(Both the text below and that in :ref:`TLV encoding section <TLV>` are adopted from an earlier packet specification draft by Mark Stapp)
18
19To minimize the overhead during early deployment and to allow flexibility of future protocol extensions to meet unforeseeable needs, both type (T) and length (L) take a variable size format.
20For implementation simplicity, both type and length take the same encoding format.
21
22We define a variable-length encoding for numbers in NDN as follows::
23
24 VAR-NUMBER := BYTE+
25
26The first octet of the number either carries the actual numeric value, or signals that a multi-octet encoding is present, as defined below:
27
28- if the first octet is < 253, the number is encoded in that octet;
29
30- if the first octet == 253, the number is encoded in the
31 following 2 octets, in net byte-order;
32
33- if the first octet == 254, the number is encoded in the
34 following 4 octets, in net byte-order;
35
36- if the first octet == 255, the number is encoded in the
37 following 8 octets, in net byte-order.
38
39
40One-octet value::
41
Alexander Afanasyeva6fc7272014-06-13 11:58:06 -070042 0 1 2 3 4 5 6 7
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000043 +---------------+
44 | < 253 = VALUE |
45 +---------------+
46
47
48Two-octet value::
49
50 1 2
Alexander Afanasyeva6fc7272014-06-13 11:58:06 -070051 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000052 +---------------+---------------+---------------+
Alexander Afanasyeva6fc7272014-06-13 11:58:06 -070053 | 253 | VALUE (MSB) VALUE (LSB) |
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000054 +---------------+---------------+---------------+
55
56Four-octet value::
57
58 1 2 3
59 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
60 +---------------+---------------+----------------+--------------+
61 | 254 | VALUE (MSB) /
62 +---------------+---------------+----------------+--------------+
63 | VALUE (LSB) |
64 +---------------+
65
66Eight-octet value::
67
68 1 2 3
69 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
70 +---------------+---------------+----------------+--------------+
71 | 255 | VALUE (MSB) /
72 +---------------+ +
73 | /
74 + +---------------+----------------+--------------+
75 | VALUE (LSB) |
76 +---------------+
77
78
79.. _TLV:
80
81TLV Encoding
82~~~~~~~~~~~~
83
84TLV encoding for NDN pakcets is defined as follows::
85
86 NDN-TLV := TLV-TYPE TLV-LENGTH TLV-VALUE?
87 TLV-TYPE := VAR-NUMBER
88 TLV-LENGTH := VAR-NUMBER
89 TLV-VALUE := BYTE+
90
91
92TLV-TYPE SHOULD be unique at all nested levels.
93The TLV Type number space and initial assignments will be specified in the later revision of the current document.
94NDN packet design will try best to keep the length of T staying with a single byte.
95
96The ``TLV-LENGTH`` value represents number of bytes that ``TLV-VALUE`` uses.
97It **does not** include number of bytes that ``TLV-TYPE`` and ``TLV-LENGTH`` fields themselves occupy.
98In particular, empty payload TLV will carry ``TLV-LENGTH`` equal to 0.
99
100
101This encoding offers a reasonable balance between compactness and flexibility.
Alexander Afanasyeva6fc7272014-06-13 11:58:06 -0700102Most common, standardized Type codes will be allocated from a small-integer number-space, and these common Types will be able to use the compact, single-byte encoding.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000103
104Non Negative Integer Encoding
105~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106
107A number of TLV elements in NDN packet format take a non-negative integer as their value, with the following definition::
108
109 nonNegativeInteger ::= BYTE+
110
111Length value of the TLV element MUST be either 1, 2, 4, or 8.
112Depending on the length value, a nonNegativeInteger is encoded as follows:
113
114- if the length is 1 (i.e. the value length is 1 octet), the nonNegativeInteger is encoded in one octet;
115
Alexander Afanasyeva6fc7272014-06-13 11:58:06 -0700116- if the length is 2 (= value length is 2 octets), the nonNegativeInteger is encoded in 2 octets, in net byte-order;
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000117
Alexander Afanasyeva6fc7272014-06-13 11:58:06 -0700118- if the length is 4 (= value length is 4 octets), the nonNegativeInteger is encoded in 4 octets, in net byte-order;
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000119
Alexander Afanasyeva6fc7272014-06-13 11:58:06 -0700120- if the length is 8 (= value length is 8 octets), the nonNegativeInteger is encoded in 8 octets, in net byte-order.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000121
122The following shows a few examples of TLVs that has nonNegativeInteger as their value component in hexadecimal format (where ``TT`` represents ``TLV-TYPE``, followed by the ``TLV-LENGTH``, then ``TLV-VALUE``)::
123
124 0 => TT0100
125 1 => TT0101
126 255 => TT01FF
127 256 => TT020100
128 65535 => TT02FFFF
129 65536 => TT0400010000