blob: d0c4e00dc8d8c7657dddd4c66dbf01957cf2a939 [file] [log] [blame]
Alexander Afanasyeve2800232013-11-27 02:24:14 +00001.. _Name:
Alexander Afanasyeveee8c252013-11-21 23:22:41 +00002
3Name
4----
5
Alexander Afanasyev406749e2014-03-27 18:45:26 -07006An NDN Name is a hierarchical name for NDN content, which contains a sequence of name components.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +00007
8NDN Name Format
9~~~~~~~~~~~~~~~
10
11We use a 2-level nested TLV to represent a name.
12The Type in the outer TLV indicates this is a Name.
Junxiao Shice743162018-04-03 00:20:50 +000013Inner TLVs should be ``NameComponent`` elements, as defined in the following:
Alexander Afanasyeve2800232013-11-27 02:24:14 +000014
15::
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000016
17 Name ::= NAME-TYPE TLV-LENGTH NameComponent*
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070018
19 NameComponent ::= GenericNameComponent |
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050020 ImplicitSha256DigestComponent |
21 OtherTypeComponent
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070022
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050023 GenericNameComponent ::= NAME-COMPONENT-TYPE TLV-LENGTH
24 BYTE*
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070025
26 ImplicitSha256DigestComponent ::= IMPLICIT-SHA256-DIGEST-COMPONENT-TYPE TLV-LENGTH(=32)
27 BYTE{32}
28
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050029 OtherTypeComponent ::= OTHER-TYPE-COMPONENT-TYPE TLV-LENGTH
30 BYTE*
31
32 OTHER-TYPE-COMPONENT-TYPE ::= number in the range 2-65535 inclusive except 8
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070033
34- ``GenericNameComponent`` is a generic name component, without any restrictions on the content of the value.
35
36- ``ImplicitSha256DigestComponent`` is an implicit SHA256 digest component and it is required to contain a value of 32 octets.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000037
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050038In addition to two component types, ``Name`` can include other component types governed by `Name Component Assignment policy <https://redmine.named-data.net/projects/ndn-tlv/wiki/NameComponentType>`__.
39
40TLV-TYPE of name component MUST be in the range ``1-65535`` (inclusive).
41``Name`` element containing a sub-element out of this range is invalid and the packet SHOULD be dropped.
42
43Name component with TLV-TYPE ``0`` (zero) is reserved to indicate an invalid name component.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000044
45NDN URI Scheme
46~~~~~~~~~~~~~~
47
48For textual representation, it is often convenient to use URI to represent NDN names.
49Please refer to RFC 3986 (URI Generic Syntax) for background.
50
Alexander Afanasyev406749e2014-03-27 18:45:26 -070051- The scheme identifier is ``ndn``.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000052
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000053- The authority component (the part after the initial ``//`` in the familiar http and ftp URI schemes) is not relevant to NDN.
Alexander Afanasyev406749e2014-03-27 18:45:26 -070054 It should not be present, and it is ignored if it is present.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000055
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070056- Component types have the following URI representations:
57
58 * ``GenericNameComponent``
59
60 + When producing a URI from an NDN Name, only the generic URI unreserved characters are left unescaped.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050061 These are the US-ASCII upper and lower case letters (A-Z, a-z), digits (0-9), and the four specials HYPHEN (-), PERIOD (.), UNDERSCORE (\_), and TILDE (~).
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070062 All other characters are escaped using the percent-encoding method of the URI Generic Syntax.
63
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070064 + To unambiguously represent name components that would collide with the use of . and .. for relative URIs, any component that consists solely of zero or more periods is encoded using three additional periods.
65
66 * ``ImplicitSha256DigestComponent``
67
Steve DiBenedetto99b8a842014-12-22 14:56:16 -070068 + Implicit SHA256 digest component starts with ``sha256digest=`` prefix (case sensitive), followed by the digest represented as a sequence of 64 hexadecimal numbers.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070069
70 For example, ``sha256digest=893259d98aca58c451453f29ec7dc38688e690dd0b59ef4f3b9d33738bff0b8d``
71
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050072 * Other component types
73
74 + Start with ``<number>=`` prefix (e.g., ``42=...``), followed by the value encoded in the same way as for ``GenericNameComponent``
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070075
76.. _Implicit Digest Component:
77
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000078Implicit Digest Component
79~~~~~~~~~~~~~~~~~~~~~~~~~
80
Alexander Afanasyev072acbd2014-10-16 12:18:13 -070081The full name of every Data packet includes a logical final implicit digest component, which makes the name of every Data packet unique.
Junxiao Shice743162018-04-03 00:20:50 +000082The implicit digest (``ImplicitSha256DigestComponent``) MAY appear in an Interest as the last component of the Interest name to request a specific Data packet.
Alexander Afanasyev072acbd2014-10-16 12:18:13 -070083``ImplicitSha256DigestComponent`` is never included explicitly in the Data packet when it is transmitted on the wire and, if needed, must be computed by all nodes based on the Data packet content.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000084
Junxiao Shice743162018-04-03 00:20:50 +000085The **implicit digest component** consists of the SHA-256 digest of the entire Data packet bits. Having this digest as the last name component allows identifying one specific Data packet and no other.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000086
87Canonical Order
88~~~~~~~~~~~~~~~
89
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050090
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070091In several contexts in NDN packet processing, it is necessary to have a consistent ordering of names and name components.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000092
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070093The order between individual name components is defined as follows:
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000094
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050095- If components have different type ``component1`` and ``component2``, then
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000096
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050097 + ``component1`` is less than ``component2`` if numerical value of ``TLV-CODE(component1)`` is less than numerical value of ``TLV-CODE(component2)``
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070098
99 .. note::
Alexander Afanasyeve9f48512018-01-15 23:44:50 -0500100 Type code ``ImplicitSha256DigestComponent`` is guaranteed to be less than type code of any other valid name component.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700101
102- If components have the same type, then
103
104 + If *a* is shorter than *b* (i.e., has fewer bytes), then *a* comes before *b*.
105
106 + If *a* and *b* have the same length, then they are compared in lexicographic order based on absolute value of octet values (e.g., ordering based on memcmp() operation.)
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000107
108For Names, the ordering is just based on the ordering of the first component where they differ.
109If one name is a proper prefix of the other, then it comes first.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -0500110
111.. note::
112 The canonical order can be enforced by directly comparing the wire encoding of the ``Name`` field's TLV-VALUE (i.e., excluding TLV-TYPE and TLV-LEGNTH of the whole Name TLV)::
113
114 int
115 canonicalOrder(Name lhs, Name rhs) {
116 int result = memcmp(lhs.value(), rhs.value(), min(lhs.value_size(), rhs.value_size());
117 if (result == 0) {
118 result = lhs.value_size() - rhs.value_size();
119 }
120 return result;
121 }