blob: 96a1c23f035307360511d24920bf442e21af2e5c [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
Junxiao Shi78ce2952019-05-07 15:34:00 -040017 Name = NAME-TYPE TLV-LENGTH *NameComponent
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070018
Junxiao Shi78ce2952019-05-07 15:34:00 -040019 NameComponent = GenericNameComponent /
20 ImplicitSha256DigestComponent /
21 ParametersSha256DigestComponent /
22 OtherTypeComponent
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070023
Junxiao Shi78ce2952019-05-07 15:34:00 -040024 GenericNameComponent = GENERIC-NAME-COMPONENT-TYPE TLV-LENGTH *OCTET
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070025
Junxiao Shi78ce2952019-05-07 15:34:00 -040026 ImplicitSha256DigestComponent = IMPLICIT-SHA256-DIGEST-COMPONENT-TYPE
27 TLV-LENGTH ; == 32
28 32OCTET
Alexander Afanasyev4b8be212014-10-06 10:55:04 -070029
Junxiao Shi78ce2952019-05-07 15:34:00 -040030 ParametersSha256DigestComponent = PARAMETERS-SHA256-DIGEST-COMPONENT-TYPE
31 TLV-LENGTH ; == 32
32 32OCTET
Alexander Afanasyev9013a562018-08-08 09:48:41 -040033
Junxiao Shi78ce2952019-05-07 15:34:00 -040034 OtherTypeComponent = OTHER-TYPE-COMPONENT-TYPE TLV-LENGTH *OCTET
Alexander Afanasyeve9f48512018-01-15 23:44:50 -050035
Junxiao Shi78ce2952019-05-07 15:34:00 -040036 ; OTHER-TYPE-COMPONENT-TYPE is a TLV-TYPE in the range 1-65535 (inclusive) other than the above defined types
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
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000050NDN URI Scheme
51~~~~~~~~~~~~~~
52
53For textual representation, it is often convenient to use URI to represent NDN names.
54Please refer to RFC 3986 (URI Generic Syntax) for background.
55
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
96.. _Implicit Digest Component:
97
Alexander Afanasyeveee8c252013-11-21 23:22:41 +000098Implicit Digest Component
99~~~~~~~~~~~~~~~~~~~~~~~~~
100
Alexander Afanasyev072acbd2014-10-16 12:18:13 -0700101The 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 +0000102The 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 -0700103``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 +0000104
Junxiao Shice743162018-04-03 00:20:50 +0000105The **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 +0000106
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400107.. _Interest Parameters Digest Component:
108
109Parameters Digest Component
110~~~~~~~~~~~~~~~~~~~~~~~~~~~
111
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
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000120Canonical Order
121~~~~~~~~~~~~~~~
122
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700123In 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 +0000124
Alexander Afanasyev4b8be212014-10-06 10:55:04 -0700125The order between individual name components is defined as follows:
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000126
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400127- If components ``component1`` and ``component2`` have different types, then
Alexander Afanasyeveee8c252013-11-21 23:22:41 +0000128
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400129 + ``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 -0700130
131 .. note::
Alexander Afanasyev9013a562018-08-08 09:48:41 -0400132 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 -0700133
134- If components have the same type, then
135
136 + If *a* is shorter than *b* (i.e., has fewer bytes), then *a* comes before *b*.
137
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
143.. note::
Davide Pesaventoec746762020-06-24 22:57:31 -0400144 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 Pesaventoec746762020-06-24 22:57:31 -0400146 .. code-block:: c
147
148 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 }