blob: 3a880310aea0888a5caf909a8f4e6e1d1bea9a00 [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.
Alexander Afanasyev9013a562018-08-08 09:48:41 -040012The NAME-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 |
Alexander Afanasyev9013a562018-08-08 09:48:41 -040021 ParametersSha256DigestComponent |
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050022 OtherTypeComponent
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070023
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050024 GenericNameComponent ::= NAME-COMPONENT-TYPE TLV-LENGTH
25 BYTE*
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070026
27 ImplicitSha256DigestComponent ::= IMPLICIT-SHA256-DIGEST-COMPONENT-TYPE TLV-LENGTH(=32)
28 BYTE{32}
29
Alexander Afanasyev9013a562018-08-08 09:48:41 -040030 ParametersSha256DigestComponent ::= PARAMETERS-SHA256-DIGEST-COMPONENT-TYPE TLV-LENGTH(=32)
31 BYTE{32}
32
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050033 OtherTypeComponent ::= OTHER-TYPE-COMPONENT-TYPE TLV-LENGTH
34 BYTE*
35
Alexander Afanasyev9013a562018-08-08 09:48:41 -040036 OTHER-TYPE-COMPONENT-TYPE ::= number in the range 3-65535 inclusive except 8
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070037
38- ``GenericNameComponent`` is a generic name component, without any restrictions on the content of the value.
39
Alexander Afanasyev9013a562018-08-08 09:48:41 -040040- ``ImplicitSha256DigestComponent`` is an implicit SHA-256 digest component and it is required to contain a value of 32 octets.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000041
Alexander Afanasyev9013a562018-08-08 09:48:41 -040042- ``ParametersSha256DigestComponent`` is a component carrying the SHA-256 digest of Interest parameters and it is required to contain a value of 32 octets.
43
44In addition to the above component types, ``Name`` can include other component types governed by `Name Component Assignment policy <https://redmine.named-data.net/projects/ndn-tlv/wiki/NameComponentType>`__.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050045
46TLV-TYPE of name component MUST be in the range ``1-65535`` (inclusive).
47``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 -040048This requirement overrides the TLV evolvability guidelines.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050049
50Name component with TLV-TYPE ``0`` (zero) is reserved to indicate an invalid name component.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000051
52NDN URI Scheme
53~~~~~~~~~~~~~~
54
55For textual representation, it is often convenient to use URI to represent NDN names.
56Please refer to RFC 3986 (URI Generic Syntax) for background.
57
Alexander Afanasyev9013a562018-08-08 09:48:41 -040058The scheme identifier is ``ndn``.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000059
Alexander Afanasyev9013a562018-08-08 09:48:41 -040060The authority component (the part after the initial ``//`` in the familiar http and ftp URI schemes) is irrelevant to NDN.
61It should not be present, and it is ignored if it is present.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000062
Alexander Afanasyev9013a562018-08-08 09:48:41 -040063Each name component is represented as ``<type-number>=<escaped-value>``, where:
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070064
Alexander Afanasyev9013a562018-08-08 09:48:41 -040065- ``<type-number>`` is the component's TLV-TYPE in decimal format without leading zeros.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070066
Alexander Afanasyev9013a562018-08-08 09:48:41 -040067- ``<escaped-value>`` is the component's TLV-VALUE escaped according to the following rules:
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070068
Alexander Afanasyev9013a562018-08-08 09:48:41 -040069 * Generic URI unreserved characters are left unescaped.
70 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 (~).
71 * All other characters are escaped using the percent-encoding method of the URI Generic Syntax.
72 * 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.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070073
Alexander Afanasyev9013a562018-08-08 09:48:41 -040074For example, ``42=Hello%20world`` represents a name component of TLV-TYPE 42 and TLV-VALUE "Hello world".
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070075
Alexander Afanasyev9013a562018-08-08 09:48:41 -040076Name components of the following types have alternate URI representations for better readability:
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070077
Alexander Afanasyev9013a562018-08-08 09:48:41 -040078- ``GenericNameComponent`` can have its ``<type-number>=`` prefix omitted.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070079
Alexander Afanasyev9013a562018-08-08 09:48:41 -040080 For example, ``Hello%20world`` is equivalent to ``8=Hello%20world``.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050081
Alexander Afanasyev9013a562018-08-08 09:48:41 -040082- ``ImplicitSha256DigestComponent`` can be represented as ``sha256digest=<hex-value>``.
83 ``ParametersSha256DigestComponent`` can be represented as ``params-sha256=<hex-value>``.
84
85 * The ``sha256digest=`` and ``params-sha256=`` prefixes are case sensitive.
86 * ``<hex-value>`` is the TLV-VALUE represented as a sequence of 64 hexadecimal digits.
87 Both lower-case and upper-case letters are acceptable, but lower-case is preferred.
88
89 For example, ``sha256digest=893259d98aca58c451453f29ec7dc38688e690dd0b59ef4f3b9d33738bff0b8d``, ``params-sha256=893259d98aca58c451453f29ec7dc38688e690dd0b59ef4f3b9d33738bff0b8d``
90
91- Other component types may define alternate URI representations in the form of ``<prefix>=<value>``, where:
92
93 * ``<prefix>`` is a non-empty string that starts with an upper or lower case letter and consists solely of generic URI unreserved characters.
94 * ``<value>`` is a string whose interpretation differs according to the prefix.
95
96 Such alternate representations should be defined in `Name Component Assignment policy <https://redmine.named-data.net/projects/ndn-tlv/wiki/NameComponentType>`__.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070097
98.. _Implicit Digest Component:
99
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000100Implicit Digest Component
101~~~~~~~~~~~~~~~~~~~~~~~~~
102
Alexander Afanasyev072acbd2014-10-16 12:18:13 -0700103The 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 +0000104The 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 -0700105``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 +0000106
Junxiao Shice743162018-04-03 00:20:50 +0000107The **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 +0000108
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400109.. _Interest Parameters Digest Component:
110
111Parameters Digest Component
112~~~~~~~~~~~~~~~~~~~~~~~~~~~
113
Junxiao Shif2bbb902019-03-15 14:36:30 -0400114The parameters digest component (``ParametersSha256DigestComponent``) contains the SHA-256 digest computed over the portion of an Interest starting from and including the ``ApplicationParameters`` element until the end of the Interest.
Junxiao Shif27e3212019-02-11 11:10:22 -0500115This digest provides uniqueness of the Interest name for a given set of parameters and securely ensures that the retrieved Data packet is a response generated against the correct set of parameters.
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400116
Junxiao Shif2bbb902019-03-15 14:36:30 -0400117This component MUST appear in an Interest name if the Interest contains a ``ApplicationParameters`` element.
Junxiao Shif27e3212019-02-11 11:10:22 -0500118The position of the component is determined by the application protocol.
119Generally, it should be at the end of the name but before version/segment numbers.
120Producers should recompute the digest over the specified portion of a received Interest, and drop the Interest if the computed digest does not match the parameters digest component in the name.
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400121
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000122Canonical Order
123~~~~~~~~~~~~~~~
124
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700125In 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 +0000126
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700127The order between individual name components is defined as follows:
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000128
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400129- If components ``component1`` and ``component2`` have different types, then
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000130
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400131 + ``component1`` is less than ``component2`` if numerical value of ``TLV-TYPE(component1)`` is less than numerical value of ``TLV-TYPE(component2)``
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700132
133 .. note::
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400134 Type number of ``ImplicitSha256DigestComponent`` is guaranteed to be less than type number of any other valid name component.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700135
136- If components have the same type, then
137
138 + If *a* is shorter than *b* (i.e., has fewer bytes), then *a* comes before *b*.
139
140 + 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 +0000141
142For Names, the ordering is just based on the ordering of the first component where they differ.
143If one name is a proper prefix of the other, then it comes first.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -0500144
145.. note::
146 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)::
147
148 int
149 canonicalOrder(Name lhs, Name rhs) {
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400150 int result = memcmp(lhs.value(), rhs.value(), min(lhs.value_size(), rhs.value_size()));
Alexander Afanasyeve9f48512018-01-15 23:44:50 -0500151 if (result == 0) {
152 result = lhs.value_size() - rhs.value_size();
153 }
154 return result;
155 }