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. |
| 42 | |
| 43 | 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] | 44 | |
| 45 | NDN URI Scheme |
| 46 | ~~~~~~~~~~~~~~ |
| 47 | |
| 48 | For textual representation, it is often convenient to use URI to represent NDN names. |
| 49 | Please refer to RFC 3986 (URI Generic Syntax) for background. |
| 50 | |
Alexander Afanasyev | 406749e | 2014-03-27 18:45:26 -0700 | [diff] [blame] | 51 | - The scheme identifier is ``ndn``. |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 52 | |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 53 | - 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] | 54 | 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] | 55 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 56 | - Component types have the following URI representations: |
| 57 | |
| 58 | * ``GenericNameComponent`` |
| 59 | |
| 60 | + 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] | 61 | 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] | 62 | All other characters are escaped using the percent-encoding method of the URI Generic Syntax. |
| 63 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 64 | + 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. |
| 65 | |
| 66 | * ``ImplicitSha256DigestComponent`` |
| 67 | |
Steve DiBenedetto | 99b8a84 | 2014-12-22 14:56:16 -0700 | [diff] [blame] | 68 | + 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] | 69 | |
| 70 | For example, ``sha256digest=893259d98aca58c451453f29ec7dc38688e690dd0b59ef4f3b9d33738bff0b8d`` |
| 71 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 72 | * Other component types |
| 73 | |
| 74 | + 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] | 75 | |
| 76 | .. _Implicit Digest Component: |
| 77 | |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 78 | Implicit Digest Component |
| 79 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 80 | |
Alexander Afanasyev | 072acbd | 2014-10-16 12:18:13 -0700 | [diff] [blame] | 81 | 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] | 82 | 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] | 83 | ``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] | 84 | |
Junxiao Shi | ce74316 | 2018-04-03 00:20:50 +0000 | [diff] [blame] | 85 | 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] | 86 | |
| 87 | Canonical Order |
| 88 | ~~~~~~~~~~~~~~~ |
| 89 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 90 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 91 | 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] | 92 | |
Alexander Afanasyev | 4b8be21 | 2014-10-06 10:55:04 -0700 | [diff] [blame] | 93 | The order between individual name components is defined as follows: |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 94 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 95 | - If components have different type ``component1`` and ``component2``, then |
Alexander Afanasyev | eee8c25 | 2013-11-21 23:22:41 +0000 | [diff] [blame] | 96 | |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 97 | + ``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] | 98 | |
| 99 | .. note:: |
Alexander Afanasyev | e9f4851 | 2018-01-15 23:44:50 -0500 | [diff] [blame] | 100 | 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] | 101 | |
| 102 | - If components have the same type, then |
| 103 | |
| 104 | + If *a* is shorter than *b* (i.e., has fewer bytes), then *a* comes before *b*. |
| 105 | |
| 106 | + 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] | 107 | |
| 108 | For Names, the ordering is just based on the ordering of the first component where they differ. |
| 109 | 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] | 110 | |
| 111 | .. note:: |
| 112 | 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):: |
| 113 | |
| 114 | int |
| 115 | canonicalOrder(Name lhs, Name rhs) { |
| 116 | int result = memcmp(lhs.value(), rhs.value(), min(lhs.value_size(), rhs.value_size()); |
| 117 | if (result == 0) { |
| 118 | result = lhs.value_size() - rhs.value_size(); |
| 119 | } |
| 120 | return result; |
| 121 | } |