face: reserved FaceIds and NullFace

refs #1620, #1622

Change-Id: I315ae262c7e0813a64b69d3e7d67de61b7b88c55
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index 10dbdfd..a95c562 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014,  Regents of the University of California,
+ *                      Arizona Board of Regents,
+ *                      Colorado State University,
+ *                      University Pierre & Marie Curie, Sorbonne University,
+ *                      Washington University in St. Louis,
+ *                      Beijing Institute of Technology,
+ *                      The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #include "face-table.hpp"
 #include "forwarder.hpp"
@@ -32,7 +33,7 @@
 
 FaceTable::FaceTable(Forwarder& forwarder)
   : m_forwarder(forwarder)
-  , m_lastFaceId(0)
+  , m_lastFaceId(FACEID_RESERVED_MAX)
 {
 }
 
@@ -44,18 +45,32 @@
 void
 FaceTable::add(shared_ptr<Face> face)
 {
-  if (face->getId() != INVALID_FACEID &&
-      m_faces.count(face->getId()) > 0)
-    {
-      NFD_LOG_DEBUG("Trying to add existing face id=" << face->getId() << " to the face table");
-      return;
-    }
+  if (face->getId() != INVALID_FACEID && m_faces.count(face->getId()) > 0) {
+    NFD_LOG_WARN("Trying to add existing face id=" << face->getId() << " to the face table");
+    return;
+  }
 
   FaceId faceId = ++m_lastFaceId;
+  BOOST_ASSERT(faceId > FACEID_RESERVED_MAX);
+  this->addImpl(face, faceId);
+}
+
+void
+FaceTable::addReserved(shared_ptr<Face> face, FaceId faceId)
+{
+  BOOST_ASSERT(face->getId() == INVALID_FACEID);
+  BOOST_ASSERT(m_faces.count(face->getId()) == 0);
+  BOOST_ASSERT(faceId <= FACEID_RESERVED_MAX);
+  this->addImpl(face, faceId);
+}
+
+void
+FaceTable::addImpl(shared_ptr<Face> face, FaceId faceId)
+{
   face->setId(faceId);
   m_faces[faceId] = face;
-  NFD_LOG_INFO("Added face id=" << faceId << " remote=" << face->getRemoteUri() <<
-                                              " local=" << face->getLocalUri());
+  NFD_LOG_INFO("Added face id=" << faceId << " remote=" << face->getRemoteUri()
+                                          << " local=" << face->getLocalUri());
 
   face->onReceiveInterest += bind(&Forwarder::onInterest,
                                   &m_forwarder, ref(*face), _1);