encoding: declare TLV-TYPE constants for Packet Format v0.3

refs #4527

Change-Id: I54a260971c6f3b82df53f5c387b132737f567a34
diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index fac222b..8fbe92d 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -39,7 +39,7 @@
 const size_t MAX_NDN_PACKET_SIZE = 8800;
 
 /**
- * @brief Namespace defining NDN-TLV related constants and procedures
+ * @brief Namespace defining NDN Packet Format related constants and procedures
  */
 namespace tlv {
 
@@ -57,38 +57,34 @@
   }
 };
 
-/** @brief TLV-TYPE numbers defined in NDN Packet Format
- *  @sa https://named-data.net/doc/ndn-tlv/types.html
+/** @brief TLV-TYPE numbers defined in NDN Packet Format v0.3
+ *  @sa https://named-data.net/doc/NDN-packet-spec/current/types.html
  */
 enum {
-  Interest      = 5,
-  Data          = 6,
-  Name          = 7,
+  Interest                      = 5,
+  Data                          = 6,
+  Name                          = 7,
+  GenericNameComponent          = 8,
   ImplicitSha256DigestComponent = 1,
-  GenericNameComponent = 8,
-  Selectors     = 9,
-  Nonce         = 10,
-  InterestLifetime          = 12,
-  ForwardingHint            = 30,
-  MinSuffixComponents       = 13,
-  MaxSuffixComponents       = 14,
-  PublisherPublicKeyLocator = 15,
-  Exclude         = 16,
-  ChildSelector   = 17,
-  MustBeFresh     = 18,
-  Any             = 19,
-  MetaInfo        = 20,
-  Content         = 21,
-  SignatureInfo   = 22,
-  SignatureValue  = 23,
-  ContentType     = 24,
-  FreshnessPeriod = 25,
-  FinalBlockId    = 26,
-  SignatureType   = 27,
-  KeyLocator      = 28,
-  KeyDigest       = 29,
-  LinkPreference  = 30,
-  LinkDelegation  = 31,
+  CanBePrefix                   = 33,
+  MustBeFresh                   = 18,
+  ForwardingHint                = 30,
+  Nonce                         = 10,
+  InterestLifetime              = 12,
+  HopLimit                      = 34,
+  Parameters                    = 35,
+  MetaInfo                      = 20,
+  Content                       = 21,
+  SignatureInfo                 = 22,
+  SignatureValue                = 23,
+  ContentType                   = 24,
+  FreshnessPeriod               = 25,
+  FinalBlockId                  = 26,
+  SignatureType                 = 27,
+  KeyLocator                    = 28,
+  KeyDigest                     = 29,
+  LinkDelegation                = 31,
+  LinkPreference                = 30,
 
   NameComponentMin = 1,
   NameComponentMax = 65535,
@@ -97,6 +93,19 @@
   AppPrivateBlock2 = 32767
 };
 
+/** @brief TLV-TYPE numbers defined in NDN Packet Format v0.2 but not in v0.3
+ *  @sa https://named-data.net/doc/NDN-packet-spec/0.2.1/types.html
+ */
+enum {
+  Selectors                 = 9,
+  MinSuffixComponents       = 13,
+  MaxSuffixComponents       = 14,
+  PublisherPublicKeyLocator = 15,
+  Exclude                   = 16,
+  ChildSelector             = 17,
+  Any                       = 19,
+};
+
 constexpr int NameComponent NDN_CXX_DEPRECATED = GenericNameComponent;
 
 enum SignatureTypeValue : uint16_t {
@@ -144,6 +153,16 @@
 };
 
 /**
+ * @brief Determine whether a TLV-TYPE is "critical" for evolvability purpose.
+ * @sa https://named-data.net/doc/NDN-packet-spec/0.3/tlv.html#considerations-for-evolvability-of-tlv-based-encoding
+ */
+inline bool
+isCriticalType(uint32_t type)
+{
+  return type <= 31 || (type & 0x01);
+}
+
+/**
  * @brief Read VAR-NUMBER in NDN-TLV encoding
  * @tparam Iterator an iterator or pointer whose value is assignable to uint8_t
  *
diff --git a/tests/unit-tests/encoding/tlv.t.cpp b/tests/unit-tests/encoding/tlv.t.cpp
index 6a14c68..299b31c 100644
--- a/tests/unit-tests/encoding/tlv.t.cpp
+++ b/tests/unit-tests/encoding/tlv.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -39,6 +39,20 @@
 BOOST_AUTO_TEST_SUITE(Encoding)
 BOOST_AUTO_TEST_SUITE(TestTlv)
 
+BOOST_AUTO_TEST_CASE(CriticalType)
+{
+  BOOST_CHECK_EQUAL(isCriticalType(0), true);
+  BOOST_CHECK_EQUAL(isCriticalType(1), true);
+  BOOST_CHECK_EQUAL(isCriticalType(2), true);
+  BOOST_CHECK_EQUAL(isCriticalType(30), true);
+  BOOST_CHECK_EQUAL(isCriticalType(31), true);
+  BOOST_CHECK_EQUAL(isCriticalType(32), false);
+  BOOST_CHECK_EQUAL(isCriticalType(33), true);
+  BOOST_CHECK_EQUAL(isCriticalType(34), false);
+  BOOST_CHECK_EQUAL(isCriticalType(10000), false);
+  BOOST_CHECK_EQUAL(isCriticalType(10001), true);
+}
+
 using ArrayStream = boost::iostreams::stream<boost::iostreams::array_source>;
 using StreamIterator = std::istream_iterator<uint8_t>;