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. |
| 12 | The 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 | |
| 21 | OtherTypeComponent |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 22 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 23 | GenericNameComponent ::= NAME-COMPONENT-TYPE TLV-LENGTH |
| 24 | BYTE* |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 25 | |
| 26 | ImplicitSha256DigestComponent ::= IMPLICIT-SHA256-DIGEST-COMPONENT-TYPE TLV-LENGTH(=32) |
| 27 | BYTE{32} |
| 28 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 29 | 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 Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 33 | |
| 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 Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 37 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 38 | In 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 | |
| 40 | TLV-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 Shi | 707ea00 | 2018-07-17 15:42:52 -0400 | [diff] [blame^] | 42 | This requirement overrides the TLV evolvability guidelines. |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 43 | |
| 44 | 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] | 45 | |
| 46 | NDN URI Scheme |
| 47 | ~~~~~~~~~~~~~~ |
| 48 | |
| 49 | For textual representation, it is often convenient to use URI to represent NDN names. |
| 50 | Please refer to RFC 3986 (URI Generic Syntax) for background. |
| 51 | |
Alexander Afanasyev | 406749e | 2014-03-27 18:45:26 -0700 | [diff] [blame] | 52 | - The scheme identifier is ``ndn``. |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 53 | |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 54 | - The authority component (the part after the initial ``//`` in the familiar http and ftp URI schemes) is not relevant to NDN. |
Alexander Afanasyev | 406749e | 2014-03-27 18:45:26 -0700 | [diff] [blame] | 55 | 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] | 56 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 57 | - 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 Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 62 | 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 Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 63 | All other characters are escaped using the percent-encoding method of the URI Generic Syntax. |
| 64 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 65 | + 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 DiBenedetto | 99b8a84 | 2014-12-22 14:56:16 -0700 | [diff] [blame] | 69 | + Implicit SHA256 digest component starts with ``sha256digest=`` prefix (case sensitive), followed by the digest represented as a sequence of 64 hexadecimal numbers. |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 70 | |
| 71 | For example, ``sha256digest=893259d98aca58c451453f29ec7dc38688e690dd0b59ef4f3b9d33738bff0b8d`` |
| 72 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 73 | * 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 Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 76 | |
| 77 | .. _Implicit Digest Component: |
| 78 | |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 79 | Implicit Digest Component |
| 80 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 81 | |
Alexander Afanasyev | 072acbd | 2014-10-16 12:18:13 -0700 | [diff] [blame] | 82 | 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] | 83 | 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] | 84 | ``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] | 85 | |
Junxiao Shi | ce74316 | 2018-04-03 00:20:50 +0000 | [diff] [blame] | 86 | 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] | 87 | |
| 88 | Canonical Order |
| 89 | ~~~~~~~~~~~~~~~ |
| 90 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 91 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 92 | 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] | 93 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 94 | The order between individual name components is defined as follows: |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 95 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 96 | - If components have different type ``component1`` and ``component2``, then |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 97 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 98 | + ``component1`` is less than ``component2`` if numerical value of ``TLV-CODE(component1)`` is less than numerical value of ``TLV-CODE(component2)`` |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 99 | |
| 100 | .. note:: |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 101 | Type code ``ImplicitSha256DigestComponent`` is guaranteed to be less than type code of any other valid name component. |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 102 | |
| 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 Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 108 | |
| 109 | For Names, the ordering is just based on the ordering of the first component where they differ. |
| 110 | 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] | 111 | |
| 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 | } |