blob: e42bd6b47ffb4a93533a0a073a293ad37ecedaf2 [file] [log] [blame]
Alexander Afanasyeve2800232013-11-27 02:24:14 +00001.. _Name:
Alexander Afanasyeveee8c252013-11-21 23:22:41 +00002
3Name
Davide Pesaventoec288fe2022-11-26 18:28:01 -05004====
Alexander Afanasyeveee8c252013-11-21 23:22:41 +00005
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
Davide Pesaventoec288fe2022-11-26 18:28:01 -05008
9Name TLV Encoding
10-----------------
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000011
12We use a 2-level nested TLV to represent a name.
Alexander Afanasyev9013a562018-08-08 09:48:41 -040013The NAME-TYPE in the outer TLV indicates this is a Name.
Davide Pesaventoec288fe2022-11-26 18:28:01 -050014Inner TLVs should be ``NameComponent`` elements, defined as follows::
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000015
Junxiao Shi78ce2952019-05-07 15:34:00 -040016 Name = NAME-TYPE TLV-LENGTH *NameComponent
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070017
Junxiao Shi78ce2952019-05-07 15:34:00 -040018 NameComponent = GenericNameComponent /
19 ImplicitSha256DigestComponent /
20 ParametersSha256DigestComponent /
21 OtherTypeComponent
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070022
Junxiao Shi78ce2952019-05-07 15:34:00 -040023 GenericNameComponent = GENERIC-NAME-COMPONENT-TYPE TLV-LENGTH *OCTET
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070024
Junxiao Shi78ce2952019-05-07 15:34:00 -040025 ImplicitSha256DigestComponent = IMPLICIT-SHA256-DIGEST-COMPONENT-TYPE
26 TLV-LENGTH ; == 32
27 32OCTET
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070028
Junxiao Shi78ce2952019-05-07 15:34:00 -040029 ParametersSha256DigestComponent = PARAMETERS-SHA256-DIGEST-COMPONENT-TYPE
30 TLV-LENGTH ; == 32
31 32OCTET
Alexander Afanasyev9013a562018-08-08 09:48:41 -040032
Davide Pesavento3a74e132022-11-26 22:10:21 -050033 OtherTypeComponent = OTHER-TYPE-COMPONENT-TYPE ; any unassigned number in [1, 65535]
34 TLV-LENGTH
35 *OCTET
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070036
37- ``GenericNameComponent`` is a generic name component, without any restrictions on the content of the value.
38
Alexander Afanasyev9013a562018-08-08 09:48:41 -040039- ``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 +000040
Alexander Afanasyev9013a562018-08-08 09:48:41 -040041- ``ParametersSha256DigestComponent`` is a component carrying the SHA-256 digest of Interest parameters and it is required to contain a value of 32 octets.
42
43In 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 -050044
Davide Pesavento3a74e132022-11-26 22:10:21 -050045TLV-TYPE of name component MUST be in the range [1, 65535].
46A ``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 -040047This requirement overrides the TLV evolvability guidelines.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050048
Davide Pesaventoec288fe2022-11-26 18:28:01 -050049
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000050NDN URI Scheme
Davide Pesaventoec288fe2022-11-26 18:28:01 -050051--------------
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000052
53For textual representation, it is often convenient to use URI to represent NDN names.
Davide Pesavento4d6c3572022-05-27 12:05:05 -040054Please refer to :rfc:`3986` (URI Generic Syntax) for background.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000055
Alexander Afanasyev9013a562018-08-08 09:48:41 -040056The scheme identifier is ``ndn``.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000057
Alexander Afanasyev9013a562018-08-08 09:48:41 -040058The authority component (the part after the initial ``//`` in the familiar http and ftp URI schemes) is irrelevant to NDN.
59It should not be present, and it is ignored if it is present.
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000060
Alexander Afanasyev9013a562018-08-08 09:48:41 -040061Each name component is represented as ``<type-number>=<escaped-value>``, where:
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070062
Alexander Afanasyev9013a562018-08-08 09:48:41 -040063- ``<type-number>`` is the component's TLV-TYPE in decimal format without leading zeros.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070064
Alexander Afanasyev9013a562018-08-08 09:48:41 -040065- ``<escaped-value>`` is the component's TLV-VALUE escaped according to the following rules:
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070066
Alexander Afanasyev9013a562018-08-08 09:48:41 -040067 * Generic URI unreserved characters are left unescaped.
68 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 (~).
69 * All other characters are escaped using the percent-encoding method of the URI Generic Syntax.
70 * 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 -070071
Alexander Afanasyev9013a562018-08-08 09:48:41 -040072For example, ``42=Hello%20world`` represents a name component of TLV-TYPE 42 and TLV-VALUE "Hello world".
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070073
Alexander Afanasyev9013a562018-08-08 09:48:41 -040074Name components of the following types have alternate URI representations for better readability:
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070075
Alexander Afanasyev9013a562018-08-08 09:48:41 -040076- ``GenericNameComponent`` can have its ``<type-number>=`` prefix omitted.
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070077
Alexander Afanasyev9013a562018-08-08 09:48:41 -040078 For example, ``Hello%20world`` is equivalent to ``8=Hello%20world``.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050079
Alexander Afanasyev9013a562018-08-08 09:48:41 -040080- ``ImplicitSha256DigestComponent`` can be represented as ``sha256digest=<hex-value>``.
81 ``ParametersSha256DigestComponent`` can be represented as ``params-sha256=<hex-value>``.
82
83 * The ``sha256digest=`` and ``params-sha256=`` prefixes are case sensitive.
84 * ``<hex-value>`` is the TLV-VALUE represented as a sequence of 64 hexadecimal digits.
85 Both lower-case and upper-case letters are acceptable, but lower-case is preferred.
86
87 For example, ``sha256digest=893259d98aca58c451453f29ec7dc38688e690dd0b59ef4f3b9d33738bff0b8d``, ``params-sha256=893259d98aca58c451453f29ec7dc38688e690dd0b59ef4f3b9d33738bff0b8d``
88
89- Other component types may define alternate URI representations in the form of ``<prefix>=<value>``, where:
90
91 * ``<prefix>`` is a non-empty string that starts with an upper or lower case letter and consists solely of generic URI unreserved characters.
92 * ``<value>`` is a string whose interpretation differs according to the prefix.
93
94 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 -070095
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070096
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000097Implicit Digest Component
Davide Pesaventoec288fe2022-11-26 18:28:01 -050098-------------------------
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000099
Alexander Afanasyev072acbd2014-10-16 12:18:13 -0700100The 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 +0000101The 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 -0700102``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 +0000103
Davide Pesaventoec288fe2022-11-26 18:28:01 -0500104The 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 +0000105
Davide Pesaventoec288fe2022-11-26 18:28:01 -0500106
107.. _ParametersDigestComponent:
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400108
109Parameters Digest Component
Davide Pesaventoec288fe2022-11-26 18:28:01 -0500110---------------------------
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400111
Junxiao Shif2bbb902019-03-15 14:36:30 -0400112The 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 -0500113This 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 -0400114
Junxiao Shif2bbb902019-03-15 14:36:30 -0400115This component MUST appear in an Interest name if the Interest contains a ``ApplicationParameters`` element.
Junxiao Shif27e3212019-02-11 11:10:22 -0500116The position of the component is determined by the application protocol.
117Generally, it should be at the end of the name but before version/segment numbers.
118Producers 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 -0400119
Davide Pesaventoec288fe2022-11-26 18:28:01 -0500120
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000121Canonical Order
Davide Pesaventoec288fe2022-11-26 18:28:01 -0500122---------------
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000123
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700124In 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 +0000125
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700126The order between individual name components is defined as follows:
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000127
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400128- If components ``component1`` and ``component2`` have different types, then
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000129
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400130 + ``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 -0700131
132 .. note::
Davide Pesavento23e340c2021-12-03 04:52:22 -0500133 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 -0700134
135- If components have the same type, then
136
Davide Pesavento23e340c2021-12-03 04:52:22 -0500137 + If *a* is shorter than *b* (i.e., has fewer bytes), then *a* comes before *b*.
138 + 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 +0000139
140For Names, the ordering is just based on the ordering of the first component where they differ.
141If one name is a proper prefix of the other, then it comes first.
Alexander Afanasyeve9f48512018-01-15 23:44:50 -0500142
Davide Pesavento23e340c2021-12-03 04:52:22 -0500143.. tip::
144 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-LENGTH of the Name element itself):
Alexander Afanasyeve9f48512018-01-15 23:44:50 -0500145
Davide Pesavento23e340c2021-12-03 04:52:22 -0500146 .. code-block:: cpp
Davide Pesaventoec746762020-06-24 22:57:31 -0400147
Davide Pesavento23e340c2021-12-03 04:52:22 -0500148 int canonicalOrder(Name lhs, Name rhs)
149 {
150 int result = memcmp(lhs.value(), rhs.value(), min(lhs.value_size(), rhs.value_size()));
151 if (result == 0) {
152 result = lhs.value_size() - rhs.value_size();
153 }
154 return result;
155 }