Alexander Afanasyev | e280023 | 2013-11-27 02:24:14 +0000 | [diff] [blame] | 1 | .. _Name: |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 2 | |
| 3 | Name |
| 4 | ---- |
| 5 | |
Alexander Afanasyev | 406749e | 2014-03-27 18:45:26 -0700 | [diff] [blame] | 6 | An NDN Name is a hierarchical name for NDN content, which contains a sequence of name components. |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 7 | |
| 8 | NDN Name Format |
| 9 | ~~~~~~~~~~~~~~~ |
| 10 | |
| 11 | We use a 2-level nested TLV to represent a name. |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 12 | The NAME-TYPE in the outer TLV indicates this is a Name. |
Junxiao Shi | ce74316 | 2018-04-03 00:20:50 +0000 | [diff] [blame] | 13 | Inner TLVs should be ``NameComponent`` elements, as defined in the following: |
Alexander Afanasyev | e280023 | 2013-11-27 02:24:14 +0000 | [diff] [blame] | 14 | |
| 15 | :: |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 16 | |
| 17 | Name ::= NAME-TYPE TLV-LENGTH NameComponent* |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 18 | |
| 19 | NameComponent ::= GenericNameComponent | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 20 | ImplicitSha256DigestComponent | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 21 | ParametersSha256DigestComponent | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 22 | OtherTypeComponent |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 24 | GenericNameComponent ::= NAME-COMPONENT-TYPE TLV-LENGTH |
| 25 | BYTE* |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 26 | |
| 27 | ImplicitSha256DigestComponent ::= IMPLICIT-SHA256-DIGEST-COMPONENT-TYPE TLV-LENGTH(=32) |
| 28 | BYTE{32} |
| 29 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 30 | ParametersSha256DigestComponent ::= PARAMETERS-SHA256-DIGEST-COMPONENT-TYPE TLV-LENGTH(=32) |
| 31 | BYTE{32} |
| 32 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 33 | OtherTypeComponent ::= OTHER-TYPE-COMPONENT-TYPE TLV-LENGTH |
| 34 | BYTE* |
| 35 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 36 | OTHER-TYPE-COMPONENT-TYPE ::= number in the range 3-65535 inclusive except 8 |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 37 | |
| 38 | - ``GenericNameComponent`` is a generic name component, without any restrictions on the content of the value. |
| 39 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 40 | - ``ImplicitSha256DigestComponent`` is an implicit SHA-256 digest component and it is required to contain a value of 32 octets. |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 41 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 42 | - ``ParametersSha256DigestComponent`` is a component carrying the SHA-256 digest of Interest parameters and it is required to contain a value of 32 octets. |
| 43 | |
| 44 | In 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 Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 45 | |
| 46 | TLV-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 Shi | 707ea00 | 2018-07-17 15:42:52 -0400 | [diff] [blame] | 48 | This requirement overrides the TLV evolvability guidelines. |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 49 | |
| 50 | Name component with TLV-TYPE ``0`` (zero) is reserved to indicate an invalid name component. |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 51 | |
| 52 | NDN URI Scheme |
| 53 | ~~~~~~~~~~~~~~ |
| 54 | |
| 55 | For textual representation, it is often convenient to use URI to represent NDN names. |
| 56 | Please refer to RFC 3986 (URI Generic Syntax) for background. |
| 57 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 58 | The scheme identifier is ``ndn``. |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 59 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 60 | The authority component (the part after the initial ``//`` in the familiar http and ftp URI schemes) is irrelevant to NDN. |
| 61 | It should not be present, and it is ignored if it is present. |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 62 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 63 | Each name component is represented as ``<type-number>=<escaped-value>``, where: |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 64 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 65 | - ``<type-number>`` is the component's TLV-TYPE in decimal format without leading zeros. |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 66 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 67 | - ``<escaped-value>`` is the component's TLV-VALUE escaped according to the following rules: |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 69 | * 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 Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 74 | For example, ``42=Hello%20world`` represents a name component of TLV-TYPE 42 and TLV-VALUE "Hello world". |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 75 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 76 | Name components of the following types have alternate URI representations for better readability: |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 78 | - ``GenericNameComponent`` can have its ``<type-number>=`` prefix omitted. |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 79 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 80 | For example, ``Hello%20world`` is equivalent to ``8=Hello%20world``. |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 81 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 82 | - ``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 Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 97 | |
| 98 | .. _Implicit Digest Component: |
| 99 | |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 100 | Implicit Digest Component |
| 101 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 102 | |
Alexander Afanasyev | 072acbd | 2014-10-16 12:18:13 -0700 | [diff] [blame] | 103 | The full name of every Data packet includes a logical final implicit digest component, which makes the name of every Data packet unique. |
Junxiao Shi | ce74316 | 2018-04-03 00:20:50 +0000 | [diff] [blame] | 104 | The implicit digest (``ImplicitSha256DigestComponent``) MAY appear in an Interest as the last component of the Interest name to request a specific Data packet. |
Alexander Afanasyev | 072acbd | 2014-10-16 12:18:13 -0700 | [diff] [blame] | 105 | ``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 Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 106 | |
Junxiao Shi | ce74316 | 2018-04-03 00:20:50 +0000 | [diff] [blame] | 107 | The **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 Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 108 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 109 | .. _Interest Parameters Digest Component: |
| 110 | |
| 111 | Parameters Digest Component |
| 112 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 113 | |
Junxiao Shi | f2bbb90 | 2019-03-15 14:36:30 -0400 | [diff] [blame^] | 114 | The 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 Shi | f27e321 | 2019-02-11 11:10:22 -0500 | [diff] [blame] | 115 | This 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 Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 116 | |
Junxiao Shi | f2bbb90 | 2019-03-15 14:36:30 -0400 | [diff] [blame^] | 117 | This component MUST appear in an Interest name if the Interest contains a ``ApplicationParameters`` element. |
Junxiao Shi | f27e321 | 2019-02-11 11:10:22 -0500 | [diff] [blame] | 118 | The position of the component is determined by the application protocol. |
| 119 | Generally, it should be at the end of the name but before version/segment numbers. |
| 120 | Producers 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 Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 121 | |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 122 | Canonical Order |
| 123 | ~~~~~~~~~~~~~~~ |
| 124 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 125 | In several contexts in NDN packet processing, it is necessary to have a consistent ordering of names and name components. |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 126 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 127 | The order between individual name components is defined as follows: |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 128 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 129 | - If components ``component1`` and ``component2`` have different types, then |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 130 | |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 131 | + ``component1`` is less than ``component2`` if numerical value of ``TLV-TYPE(component1)`` is less than numerical value of ``TLV-TYPE(component2)`` |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 132 | |
| 133 | .. note:: |
Alexander Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 134 | Type number of ``ImplicitSha256DigestComponent`` is guaranteed to be less than type number of any other valid name component. |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 135 | |
| 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 Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 141 | |
| 142 | For Names, the ordering is just based on the ordering of the first component where they differ. |
| 143 | If one name is a proper prefix of the other, then it comes first. |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 144 | |
| 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 Afanasyev | 9013a56 | 2018-08-08 09:48:41 -0400 | [diff] [blame] | 150 | int result = memcmp(lhs.value(), rhs.value(), min(lhs.value_size(), rhs.value_size())); |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 151 | if (result == 0) { |
| 152 | result = lhs.value_size() - rhs.value_size(); |
| 153 | } |
| 154 | return result; |
| 155 | } |