blob: 8fad77724e379a60ce4d7be38d1172a094232fbb [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.
Junxiao Shi707ea002018-07-17 15:42:52 -040042This requirement overrides the TLV evolvability guidelines.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050043
44Name component with TLV-TYPE ``0`` (zero) is reserved to indicate an invalid name component.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000045
46NDN URI Scheme
47~~~~~~~~~~~~~~
48
49For textual representation, it is often convenient to use URI to represent NDN names.
50Please refer to RFC 3986 (URI Generic Syntax) for background.
51
Alexander Afanasyev406749e2014-03-27 18:45:26 -070052- The scheme identifier is ``ndn``.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000053
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000054- 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 -070055 It should not be present, and it is ignored if it is present.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000056
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070057- Component types have the following URI representations:
58
59 * ``GenericNameComponent``
60
61 + When producing a URI from an NDN Name, only the generic URI unreserved characters are left unescaped.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050062 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 -070063 All other characters are escaped using the percent-encoding method of the URI Generic Syntax.
64
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070065 + 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.
66
67 * ``ImplicitSha256DigestComponent``
68
Steve DiBenedetto99b8a842014-12-22 14:56:16 -070069 + 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 -070070
71 For example, ``sha256digest=893259d98aca58c451453f29ec7dc38688e690dd0b59ef4f3b9d33738bff0b8d``
72
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050073 * Other component types
74
75 + 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 -070076
77.. _Implicit Digest Component:
78
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000079Implicit Digest Component
80~~~~~~~~~~~~~~~~~~~~~~~~~
81
Alexander Afanasyev072acbd2014-10-16 12:18:13 -070082The 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 +000083The 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 -070084``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 +000085
Junxiao Shice743162018-04-03 00:20:50 +000086The **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 +000087
88Canonical Order
89~~~~~~~~~~~~~~~
90
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050091
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070092In 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 +000093
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070094The order between individual name components is defined as follows:
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000095
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050096- If components have different type ``component1`` and ``component2``, then
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000097
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050098 + ``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 -070099
100 .. note::
Alexander Afanasyeve9f48512018-01-15 23:44:50 -0500101 Type code ``ImplicitSha256DigestComponent`` is guaranteed to be less than type code of any other valid name component.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700102
103- If components have the same type, then
104
105 + If *a* is shorter than *b* (i.e., has fewer bytes), then *a* comes before *b*.
106
107 + 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 +0000108
109For Names, the ordering is just based on the ordering of the first component where they differ.
110If one name is a proper prefix of the other, then it comes first.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -0500111
112.. note::
113 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)::
114
115 int
116 canonicalOrder(Name lhs, Name rhs) {
117 int result = memcmp(lhs.value(), rhs.value(), min(lhs.value_size(), rhs.value_size());
118 if (result == 0) {
119 result = lhs.value_size() - rhs.value_size();
120 }
121 return result;
122 }