tlv: !!! MAJOR CHANGE !!! Changed TLV codes

Change-Id: Id3d73db74889a13ac7db73c5f2a16d7c2c28f091
diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index 511d0f6..1ea0936 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -25,10 +25,10 @@
 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
 
 enum {
-  Interest      = 1,
-  Data          = 2,
-  Name          = 3,
-  NameComponent = 4,
+  Name          = 1,
+  NameComponent = 2,
+  Interest      = 3,
+  Data          = 4,
   Selectors     = 5,
   Nonce         = 6,
   Scope         = 7,
diff --git a/tests/management/test-ndnd-forwarding-entry.cpp b/tests/management/test-ndnd-forwarding-entry.cpp
index bd5aa9f..7e2066b 100644
--- a/tests/management/test-ndnd-forwarding-entry.cpp
+++ b/tests/management/test-ndnd-forwarding-entry.cpp
@@ -20,7 +20,7 @@
 namespace ndn {
 namespace ndnd {
 
-const uint8_t FORWARDING_ENTRY[] = {0x81, 0x19, 0x83, 0x07, 0x73, 0x65, 0x6c, 0x66, 0x72, 0x65, 0x67, 0x03, 0x0b, 0x04, 0x01, 0x61, 0x04, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x8a, 0x01, 0x03};
+const uint8_t FORWARDING_ENTRY[] = {0x81, 0x19, 0x83, 0x07, 0x73, 0x65, 0x6c, 0x66, 0x72, 0x65, 0x67, 0x01, 0x0b, 0x02, 0x01, 0x61, 0x02, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x8a, 0x01, 0x03};
 
 BOOST_AUTO_TEST_SUITE(TestForwardingEntry)
 
diff --git a/tests/management/test-nfd-control.cpp b/tests/management/test-nfd-control.cpp
index 1315627..8ba18cc 100644
--- a/tests/management/test-nfd-control.cpp
+++ b/tests/management/test-nfd-control.cpp
@@ -20,8 +20,8 @@
 const uint8_t TestControlResponse[] = {0x65, 0x17, 0x66, 0x02, 0x01, 0x94, 0x67, 0x11, 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x6f, 0x75, 0x6e, 0x64};
 
 const uint8_t TestFibManagementOptions[] = {
-  0x68, 0x1e, 0x03, 0x16, 0x04, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
-  0x6f, 0x73, 0x74, 0x04, 0x03, 0x72, 0x65, 0x67, 0x04, 0x04, 0x74, 0x65,
+  0x68, 0x1e, 0x01, 0x16, 0x02, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
+  0x6f, 0x73, 0x74, 0x02, 0x03, 0x72, 0x65, 0x67, 0x02, 0x04, 0x74, 0x65,
   0x73, 0x74, 0x69, 0x01, 0x00, 0x6a, 0x01, 0x00
 };
 
diff --git a/tests/test-certificate-cache.cpp b/tests/security/test-certificate-cache.cpp
similarity index 100%
rename from tests/test-certificate-cache.cpp
rename to tests/security/test-certificate-cache.cpp
diff --git a/tests/test-encode-decode-certificate.cpp b/tests/security/test-encode-decode-certificate.cpp
similarity index 100%
rename from tests/test-encode-decode-certificate.cpp
rename to tests/security/test-encode-decode-certificate.cpp
diff --git a/tests/test-sec-public-info-sqlite3.cpp b/tests/security/test-sec-public-info-sqlite3.cpp
similarity index 77%
rename from tests/test-sec-public-info-sqlite3.cpp
rename to tests/security/test-sec-public-info-sqlite3.cpp
index 70dd0f6..4335b71 100644
--- a/tests/test-sec-public-info-sqlite3.cpp
+++ b/tests/security/test-sec-public-info-sqlite3.cpp
@@ -25,7 +25,7 @@
   Name identity(string("/TestSecPublicInfoSqlite3/Delete/") + boost::lexical_cast<string>(time::now()));
   Name certName1;
   BOOST_REQUIRE_NO_THROW(certName1 = keyChain.createIdentity(identity));
-  
+
   Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);  
   Name keyName2;
   BOOST_CHECK_NO_THROW(keyName2 = keyChain.generateRSAKeyPairAsDefault(identity));
@@ -47,20 +47,20 @@
   Name certName5 = cert5->getName();
   keyChain.addCertificateAsKeyDefault(*cert5);
 
-  BOOST_REQUIRE_EQUAL(keyChain.doesIdentityExist(identity), true);
-  BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
-  BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
-  BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
-  BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName1), true);
-  BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName2), true);
-  BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true);
-  BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true);
-  BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName5), true);
+  BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
+  BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
+  BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
+  BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
+  BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), true);
+  BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), true);
+  BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
+  BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
+  BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), true);
 
   keyChain.deleteCertificate(certName5);
   BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false);
-  BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true);
-  BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true);
+  BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
+  BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
   BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
 
   keyChain.deleteKey(keyName3);
diff --git a/tests/test-sec-tpm-file.cpp b/tests/security/test-sec-tpm-file.cpp
similarity index 100%
rename from tests/test-sec-tpm-file.cpp
rename to tests/security/test-sec-tpm-file.cpp
diff --git a/tests/test-sec-tpm-osx.cpp b/tests/security/test-sec-tpm-osx.cpp
similarity index 100%
rename from tests/test-sec-tpm-osx.cpp
rename to tests/security/test-sec-tpm-osx.cpp
diff --git a/tests/test-signed-interest.cpp b/tests/security/test-signed-interest.cpp
similarity index 100%
rename from tests/test-signed-interest.cpp
rename to tests/security/test-signed-interest.cpp
diff --git a/tests/test-validator.cpp b/tests/security/test-validator.cpp
similarity index 100%
rename from tests/test-validator.cpp
rename to tests/security/test-validator.cpp
diff --git a/tests/test-encode-decode-data.cpp b/tests/test-data.cpp
similarity index 87%
rename from tests/test-encode-decode-data.cpp
rename to tests/test-data.cpp
index 239778b..b833efa 100644
--- a/tests/test-encode-decode-data.cpp
+++ b/tests/test-data.cpp
@@ -10,12 +10,6 @@
 
 #include <fstream>
 
-#if __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wtautological-compare"
-#endif
-
-
 #include <cryptopp/rsa.h>
 #include <cryptopp/osrng.h>
 #include <cryptopp/files.h>
@@ -28,13 +22,13 @@
 const uint8_t Content1[] = {0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x21};
 
 const uint8_t Data1[] = {
-0x02, 0xc5, // NDN Data                           
-    0x03, 0x14, // Name                           
-        0x04, 0x05,    
+0x04, 0xc5, // NDN Data                           
+    0x01, 0x14, // Name                           
+        0x02, 0x05,    
             0x6c, 0x6f, 0x63, 0x61, 0x6c,
-        0x04, 0x03,    
+        0x02, 0x03,    
             0x6e, 0x64, 0x6e,
-        0x04, 0x06,    
+        0x02, 0x06,    
             0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
     0x10, 0x04, // MetaInfo
         0x15, 0x02, // FreshnessPeriod
@@ -45,17 +39,18 @@
         0x16, 0x01, // SignatureType
             0x01,                   
         0x17, 0x16, // KeyLocator
-            0x03, 0x14, // Name  
-                0x04, 0x04,    
+            0x01, 0x14, // Name  
+                0x02, 0x04,    
                     0x74, 0x65, 0x73, 0x74,
-                0x04, 0x03,    
+                0x02, 0x03,    
                     0x6b, 0x65, 0x79,
-                0x04, 0x07,    
+                0x02, 0x07,    
                     0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
     0x13, 0x80, // SignatureValue
-        0x31, 0x32, 0xd8, 0x03, 0x9b, 0xc0, 0x7f, 0x0f, 0x97, 0xa8, 0x14, 0xa8, 0xa7, 0x69, 0xc3, 0x0b, 0xca, 0xa1, 0x82, 0x3c, 0xeb, 0xad, 0x5d, 0xb6, 0x06, 0xd9, 0x66, 0x85, 0xc6, 0x7e, 0x99, 0x38, 0xd7, 0x33, 0x9a, 0x5b, 0x48, 0x9c, 0x55, 0x6d, 0xfd, 0x7e, 0x97, 0xe2, 0x2a, 0x75, 0xc8, 0x26, 0x8e, 0x2f, 0xe3, 0xa5, 0xc3, 0xf6, 0xa6, 0xe4, 0xc8, 0x23, 0x55, 0x78, 0xff, 0x0c, 0xb1, 0x8c, 0xc2, 0x45, 0x9a, 0xec, 0x4b, 0x87, 0x2b, 0x3a, 0x8d, 0x4c, 0xc7, 0x6c, 0x92, 0xa3, 0x72, 0x0e, 0xae, 0x2e, 0x13, 0xea, 0x5d, 0x1d, 0xce, 0x63, 0x10, 0x63, 0xb2, 0x19, 0xb7, 0x67, 0xb5, 0x7d, 0xbe, 0xac, 0xaf, 0xe2, 0xed, 0x71, 0xc1, 0x47, 0x10, 0x65, 0x7c, 0x69, 0x77, 0xe7, 0xf6, 0x69, 0xd6, 0x12, 0x2b, 0x97, 0x05, 0xe1, 0x71, 0xc0, 0xae, 0xc7, 0xe1, 0x8f, 0x99, 0x32, 0x4f, 0xd7
+        0x96, 0xa7, 0x5d, 0x91, 0xc1, 0x1c, 0xa9, 0x96, 0x93, 0x7e, 0x6b, 0x2d, 0x5a, 0x86, 0x98, 0xce, 0x55, 0xb8, 0x4a, 0x91, 0xc6, 0x5d, 0x69, 0x71, 0x47, 0x0c, 0x6b, 0x70, 0xa2, 0x82, 0xef, 0x48, 0x69, 0x24, 0x71, 0xd5, 0xb2, 0xda, 0x6d, 0x26, 0xde, 0x8d, 0xb8, 0x37, 0x8e, 0xd7, 0xc2, 0xd9, 0xad, 0xd9, 0x97, 0xf8, 0xdd, 0xab, 0x36, 0x49, 0x77, 0xff, 0x12, 0x83, 0xa3, 0x0b, 0xf0, 0xac, 0x52, 0x08, 0xb5, 0xa4, 0x67, 0x16, 0x2a, 0x5e, 0x76, 0xc3, 0x06, 0x27, 0x3e, 0x5b, 0x13, 0x26, 0x18, 0x9c, 0x0d, 0x22, 0xb8, 0x9c, 0x24, 0x63, 0x06, 0x73, 0xe8, 0xc1, 0x27, 0x21, 0xe3, 0x92, 0x88, 0x49, 0xf3, 0xc3, 0xa8, 0xc5, 0xa8, 0x74, 0x57, 0xf9, 0xd6, 0x0c, 0x4f, 0x97, 0x9a, 0x7e, 0x7c, 0x03, 0xdb, 0x47, 0x11, 0xa0, 0xaf, 0x67, 0x44, 0x54, 0x66, 0x0e, 0x12, 0xd6, 0x39, 0xb3
 };
 
+
 const unsigned char DEFAULT_PRIVATE_KEY_DER[] = {
 0x30, 0x82, 0x02, 0x74, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
 0x05, 0x00, 0x04, 0x82, 0x02, 0x5e, 0x30, 0x82, 0x02, 0x5a, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0x9e, 0x06, 0x3e,
diff --git a/tests/test-encode-decode-block.cpp b/tests/test-encode-decode-block.cpp
deleted file mode 100644
index 9e5e01c..0000000
--- a/tests/test-encode-decode-block.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * See COPYING for copyright and distribution information.
- */
-
-#include <boost/test/unit_test.hpp>
-
-#include "interest.hpp"
-
-using namespace std;
-
-namespace ndn {
-
-BOOST_AUTO_TEST_SUITE(TestBlock)
-
-const uint8_t Interest1[] = {
-  0x1,  0x41, // NDN Interest
-      0x3,  0x14, // Name
-          0x4,  0x5, // NameComponent
-              0x6c,  0x6f,  0x63,  0x61,  0x6c,
-          0x4,  0x3, // NameComponent
-              0x6e,  0x64,  0x6e,
-          0x4,  0x6, // NameComponent
-              0x70,  0x72,  0x65,  0x66,  0x69,  0x78,
-      0x5,  0x1f, // Selectors
-          0x09,  0x1,  0x1,  // MinSuffix
-          0x0a,  0x1,  0x1,  // MaxSuffix
-          0x0c,  0x14, // Exclude
-              0x4,  0x4, // NameComponent
-                  0x61,  0x6c,  0x65,  0x78,
-              0x4,  0x4, // NameComponent
-                  0x78,  0x78,  0x78,  0x78,
-              0xf,  0x0, // Any
-              0x4,  0x4, // NameComponent
-                  0x79,  0x79,  0x79,  0x79,
-          0x0d,  0x1, // ChildSelector
-              0x1,
-      0x6,  0x1, // Nonce
-          0x1,
-      0x7,  0x1, // Scope
-          0x1,
-      0x8,       // InterestLifetime
-          0x2,  0x3,  0xe8
-};
-
-BOOST_AUTO_TEST_CASE (Decode)
-{
-  boost::iostreams::stream<boost::iostreams::array_source> is (reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
-  
-  Block interestBlock(is);
-
-  ndn::Interest i;
-  BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
-
-  BOOST_REQUIRE_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
-  BOOST_REQUIRE_EQUAL(i.getScope(), 1);
-  BOOST_REQUIRE_EQUAL(i.getInterestLifetime(), 1000);
-  BOOST_REQUIRE_EQUAL(i.getMinSuffixComponents(), 1);
-  BOOST_REQUIRE_EQUAL(i.getMaxSuffixComponents(), 1);
-  BOOST_REQUIRE_EQUAL(i.getChildSelector(), 1);
-  BOOST_REQUIRE_EQUAL(i.getMustBeFresh(), false);
-  BOOST_REQUIRE_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
-  BOOST_REQUIRE_EQUAL(i.getNonce(), 1);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace ndn
diff --git a/tests/test-encode-decode-interest.cpp b/tests/test-interest.cpp
similarity index 67%
rename from tests/test-encode-decode-interest.cpp
rename to tests/test-interest.cpp
index 4c6daaa..254bd48 100644
--- a/tests/test-encode-decode-interest.cpp
+++ b/tests/test-interest.cpp
@@ -13,24 +13,24 @@
 BOOST_AUTO_TEST_SUITE(TestInterest)
 
 const uint8_t Interest1[] = {
-  0x1,  0x41, // NDN Interest
-      0x3,  0x14, // Name
-          0x4,  0x5, // NameComponent
+  0x3,  0x41, // NDN Interest
+      0x1,  0x14, // Name
+          0x2,  0x5, // NameComponent
               0x6c,  0x6f,  0x63,  0x61,  0x6c,
-          0x4,  0x3, // NameComponent
+          0x2,  0x3, // NameComponent
               0x6e,  0x64,  0x6e,
-          0x4,  0x6, // NameComponent
+          0x2,  0x6, // NameComponent
               0x70,  0x72,  0x65,  0x66,  0x69,  0x78,
       0x5,  0x1f, // Selectors
           0x09,  0x1,  0x1,  // MinSuffix
           0x0a,  0x1,  0x1,  // MaxSuffix
           0x0c,  0x14, // Exclude
-              0x4,  0x4, // NameComponent
+              0x2,  0x4, // NameComponent
                   0x61,  0x6c,  0x65,  0x78,
-              0x4,  0x4, // NameComponent
+              0x2,  0x4, // NameComponent
                   0x78,  0x78,  0x78,  0x78,
               0xf,  0x0, // Any
-              0x4,  0x4, // NameComponent
+              0x2,  0x4, // NameComponent
                   0x79,  0x79,  0x79,  0x79,
           0x0d,  0x1, // ChildSelector
               0x1,
@@ -60,6 +60,26 @@
   BOOST_REQUIRE_EQUAL(i.getNonce(), 1);
 }
 
+BOOST_AUTO_TEST_CASE (DecodeFromStream)
+{
+  boost::iostreams::stream<boost::iostreams::array_source> is (reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
+  
+  Block interestBlock(is);
+
+  ndn::Interest i;
+  BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
+
+  BOOST_REQUIRE_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
+  BOOST_REQUIRE_EQUAL(i.getScope(), 1);
+  BOOST_REQUIRE_EQUAL(i.getInterestLifetime(), 1000);
+  BOOST_REQUIRE_EQUAL(i.getMinSuffixComponents(), 1);
+  BOOST_REQUIRE_EQUAL(i.getMaxSuffixComponents(), 1);
+  BOOST_REQUIRE_EQUAL(i.getChildSelector(), 1);
+  BOOST_REQUIRE_EQUAL(i.getMustBeFresh(), false);
+  BOOST_REQUIRE_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
+  BOOST_REQUIRE_EQUAL(i.getNonce(), 1);
+}
+
 BOOST_AUTO_TEST_CASE (Encode)
 {
   ndn::Interest i(ndn::Name("/local/ndn/prefix"));
diff --git a/tests/test-name.cpp b/tests/test-name.cpp
index cabfd2f..961f98e 100644
--- a/tests/test-name.cpp
+++ b/tests/test-name.cpp
@@ -12,12 +12,12 @@
 BOOST_AUTO_TEST_SUITE(TestName)
 
 static const uint8_t TestName[] = {
-        0x3,  0x14, // Name
-          0x4,  0x5, // NameComponent
+        0x1,  0x14, // Name
+          0x2,  0x5, // NameComponent
               0x6c,  0x6f,  0x63,  0x61,  0x6c,
-          0x4,  0x3, // NameComponent
+          0x2,  0x3, // NameComponent
               0x6e,  0x64,  0x6e,
-          0x4,  0x6, // NameComponent
+          0x2,  0x6, // NameComponent
               0x70,  0x72,  0x65,  0x66,  0x69,  0x78
 };
 
@@ -59,8 +59,8 @@
 {
   Name name("/local");
 
-  const uint8_t name1[] = {0x3,  0x7, // Name
-                           0x4,  0x5, // NameComponent
+  const uint8_t name1[] = {0x1,  0x7, // Name
+                           0x2,  0x5, // NameComponent
                            0x6c,  0x6f,  0x63,  0x61,  0x6c};
   
   BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
@@ -68,10 +68,10 @@
 
   name.append("ndn");
   
-  const uint8_t name2[] = {0x3,  0xc, // Name
-                           0x4,  0x5, // NameComponent
+  const uint8_t name2[] = {0x1,  0xc, // Name
+                           0x2,  0x5, // NameComponent
                            0x6c,  0x6f,  0x63,  0x61,  0x6c,
-                           0x4,  0x3, // NameComponent
+                           0x2,  0x3, // NameComponent
                            0x6e,  0x64,  0x6e};
   
   BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
diff --git a/tests/test-regex.cpp b/tests/util/test-regex.cpp
similarity index 100%
rename from tests/test-regex.cpp
rename to tests/util/test-regex.cpp
diff --git a/tests/test-scheduler.cpp b/tests/util/test-scheduler.cpp
similarity index 100%
rename from tests/test-scheduler.cpp
rename to tests/util/test-scheduler.cpp
diff --git a/tests/test-time.cpp b/tests/util/test-time.cpp
similarity index 100%
rename from tests/test-time.cpp
rename to tests/util/test-time.cpp
diff --git a/tools/tlvdump.cpp b/tools/tlvdump.cpp
index 3c9bd81..1b94630 100644
--- a/tools/tlvdump.cpp
+++ b/tools/tlvdump.cpp
@@ -11,14 +11,14 @@
 #include <iomanip>
 #include <fstream>
 
-const uint32_t TLV_DICT_SIZE = 25;
+const uint32_t TLV_DICT_SIZE = 26;
 
 const std::string TLV_DICT[TLV_DICT_SIZE] = {
   "RESERVED", //      = 0
-  "Interest", //      = 1,
-  "Data", //          = 2,
-  "Name", //          = 3,
-  "NameComponent", // = 4,
+  "Name", //          = 1,
+  "NameComponent", // = 2,
+  "Interest", //      = 3,
+  "Data", //          = 4,
   "Selectors", //     = 5,
   "Nonce", //         = 6,
   "Scope", //         = 7,
@@ -39,6 +39,7 @@
   "SignatureType", // = 22,
   "KeyLocator", //    = 23,
   "KeyLocatorDigest", // = 24
+  "FinalBlockId" // = 25
 };
 
 void