fw: Prevent re-insertion of faces into FaceTable

Change-Id: I48c92af965001e15af06b39de76893ce6a736b94
Refs: #1413
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index 35bf377..ca7b56f 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.cpp
@@ -25,6 +25,13 @@
 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;
+    }
+
   FaceId faceId = ++m_lastFaceId;
   face->setId(faceId);
   m_faces[faceId] = face;
diff --git a/tests/fw/face-table.cpp b/tests/fw/face-table.cpp
index 492d633..9d1d930 100644
--- a/tests/fw/face-table.cpp
+++ b/tests/fw/face-table.cpp
@@ -44,6 +44,11 @@
   BOOST_CHECK_NE(face2->getId(), INVALID_FACEID);
   BOOST_CHECK_NE(face1->getId(), face2->getId());
 
+  FaceId oldId1 = face1->getId();
+  faceTable.add(face1);
+  BOOST_CHECK_EQUAL(face1->getId(), oldId1);
+  BOOST_CHECK_EQUAL(faceTable.size(), 2);
+
   BOOST_REQUIRE_EQUAL(onAddHistory.size(), 2);
   BOOST_CHECK_EQUAL(onAddHistory[0], face1->getId());
   BOOST_CHECK_EQUAL(onAddHistory[1], face2->getId());