face: replace isOnDemand with FacePersistency

Change-Id: Ie6995b2d03bbb90faad158de2b055f72dd9ba73d
Refs: #2989
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index 0974cf2..0dd8169 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -34,7 +34,7 @@
   , m_remoteUri(remoteUri)
   , m_localUri(localUri)
   , m_isLocal(isLocal)
-  , m_isOnDemand(false)
+  , m_persistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
   , m_isMultiAccess(isMultiAccess)
   , m_isFailed(false)
 {
@@ -102,8 +102,7 @@
         .setLocalUri(getLocalUri().toString())
         .setFaceScope(isLocal() ? ndn::nfd::FACE_SCOPE_LOCAL
                                 : ndn::nfd::FACE_SCOPE_NON_LOCAL)
-        .setFacePersistency(isOnDemand() ? ndn::nfd::FACE_PERSISTENCY_ON_DEMAND
-                                         : ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
+        .setFacePersistency(getPersistency())
         .setLinkType(isMultiAccess() ? ndn::nfd::LINK_TYPE_MULTI_ACCESS
                                      : ndn::nfd::LINK_TYPE_POINT_TO_POINT);
 }
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index 58deb3d..a5923d2 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -128,10 +128,10 @@
   bool
   isLocal() const;
 
-  /** \brief Get whether face is created on demand or explicitly via FaceManagement protocol
+  /** \brief Get the persistency setting
    */
-  bool
-  isOnDemand() const;
+  ndn::nfd::FacePersistency
+  getPersistency() const;
 
   /** \brief Get whether packets sent by this face may reach multiple peers
    */
@@ -171,7 +171,7 @@
 
 PUBLIC_WITH_TESTS_ELSE_PROTECTED:
   void
-  setOnDemand(bool isOnDemand);
+  setPersistency(ndn::nfd::FacePersistency persistency);
 
 protected:
   bool
@@ -202,7 +202,7 @@
   const FaceUri m_remoteUri;
   const FaceUri m_localUri;
   const bool m_isLocal;
-  bool m_isOnDemand;
+  ndn::nfd::FacePersistency m_persistency;
   const bool m_isMultiAccess;
   bool m_isFailed;
 
@@ -240,16 +240,16 @@
   return m_isLocal;
 }
 
-inline bool
-Face::isOnDemand() const
+inline ndn::nfd::FacePersistency
+Face::getPersistency() const
 {
-  return m_isOnDemand;
+  return m_persistency;
 }
 
 inline void
-Face::setOnDemand(bool isOnDemand)
+Face::setPersistency(ndn::nfd::FacePersistency persistency)
 {
-  m_isOnDemand = isOnDemand;
+  m_persistency = persistency;
 }
 
 inline bool
diff --git a/daemon/face/stream-face.hpp b/daemon/face/stream-face.hpp
index 94c339a..d08c1d5 100644
--- a/daemon/face/stream-face.hpp
+++ b/daemon/face/stream-face.hpp
@@ -120,7 +120,7 @@
 {
   NFD_LOG_FACE_INFO("Creating face");
 
-  this->setOnDemand(isOnDemand);
+  this->setPersistency(isOnDemand ? ndn::nfd::FACE_PERSISTENCY_ON_DEMAND : ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
   StreamFaceValidator<T, FaceBase>::validateSocket(m_socket);
 
   m_socket.async_receive(boost::asio::buffer(m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE),
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index c0d0d3c..81cf401 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -98,9 +98,10 @@
   auto it = m_channelFaces.find(remoteEndpoint);
   if (it != m_channelFaces.end()) {
     // we already have a face for this endpoint, just reuse it
-    if (!isOnDemand)
-      // only on-demand -> non-on-demand transition is allowed
-      it->second->setOnDemand(false);
+    if (!isOnDemand) {
+      // only on-demand -> persistent transition is allowed
+      it->second->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
+    }
     return {false, it->second};
   }
 
diff --git a/daemon/face/udp-face.cpp b/daemon/face/udp-face.cpp
index a854cc4..20b57cf 100644
--- a/daemon/face/udp-face.cpp
+++ b/daemon/face/udp-face.cpp
@@ -44,7 +44,7 @@
   , m_idleTimeout(idleTimeout)
   , m_lastIdleCheck(time::steady_clock::now())
 {
-  this->setOnDemand(isOnDemand);
+  this->setPersistency(isOnDemand ? ndn::nfd::FACE_PERSISTENCY_ON_DEMAND : ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
 
 #ifdef __linux__
   //
@@ -66,7 +66,7 @@
   }
 #endif
 
-  if (this->isOnDemand() && m_idleTimeout > time::seconds::zero()) {
+  if (this->getPersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND && m_idleTimeout > time::seconds::zero()) {
     m_closeIfIdleEvent = scheduler::schedule(m_idleTimeout, bind(&UdpFace::closeIfIdle, this));
   }
 }
@@ -76,7 +76,7 @@
 {
   auto status = DatagramFace::getFaceStatus();
 
-  if (isOnDemand()) {
+  if (this->getPersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
     time::milliseconds left = m_idleTimeout;
     left -= time::duration_cast<time::milliseconds>(time::steady_clock::now() - m_lastIdleCheck);
 
@@ -97,7 +97,7 @@
 {
   // Face can be switched from on-demand to non-on-demand mode
   // (non-on-demand -> on-demand transition is not allowed)
-  if (isOnDemand()) {
+  if (this->getPersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
     if (!hasBeenUsedRecently()) {
       NFD_LOG_FACE_INFO("Closing for inactivity");
       close();
diff --git a/daemon/face/websocket-face.cpp b/daemon/face/websocket-face.cpp
index 4c781c3..3b94e6e 100644
--- a/daemon/face/websocket-face.cpp
+++ b/daemon/face/websocket-face.cpp
@@ -38,7 +38,7 @@
   , m_closed(false)
 {
   NFD_LOG_FACE_INFO("Creating face");
-  this->setOnDemand(true);
+  this->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
 }
 
 void
diff --git a/daemon/mgmt/face-query-status-publisher.cpp b/daemon/mgmt/face-query-status-publisher.cpp
index 59cf513..e60b949 100644
--- a/daemon/mgmt/face-query-status-publisher.cpp
+++ b/daemon/mgmt/face-query-status-publisher.cpp
@@ -74,8 +74,7 @@
   }
 
   if (m_faceFilter.hasFacePersistency() &&
-      (m_faceFilter.getFacePersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) !=
-      face->isOnDemand()) {
+      m_faceFilter.getFacePersistency() != face->getPersistency()) {
     return false;
   }
 
diff --git a/tests/daemon/face/ethernet.t.cpp b/tests/daemon/face/ethernet.t.cpp
index 6b7a0bb..e0e08f8 100644
--- a/tests/daemon/face/ethernet.t.cpp
+++ b/tests/daemon/face/ethernet.t.cpp
@@ -113,7 +113,7 @@
 
   BOOST_REQUIRE(static_cast<bool>(face));
   BOOST_CHECK_EQUAL(face->isLocal(), false);
-  BOOST_CHECK_EQUAL(face->isOnDemand(), false);
+  BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
   BOOST_CHECK_EQUAL(face->isMultiAccess(), true);
   BOOST_CHECK_EQUAL(face->getRemoteUri().toString(),
                     "ether://[" + ethernet::getDefaultMulticastAddress().toString() + "]");
diff --git a/tests/daemon/face/tcp.t.cpp b/tests/daemon/face/tcp.t.cpp
index dc788fc..2f85e37 100644
--- a/tests/daemon/face/tcp.t.cpp
+++ b/tests/daemon/face/tcp.t.cpp
@@ -275,8 +275,8 @@
   BOOST_REQUIRE(static_cast<bool>(face1));
   BOOST_REQUIRE(static_cast<bool>(face2));
 
-  BOOST_CHECK_EQUAL(face1->isOnDemand(), true);
-  BOOST_CHECK_EQUAL(face2->isOnDemand(), false);
+  BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+  BOOST_CHECK_EQUAL(face2->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
   BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);
   BOOST_CHECK_EQUAL(face2->isMultiAccess(), false);
 
diff --git a/tests/daemon/face/udp.t.cpp b/tests/daemon/face/udp.t.cpp
index ea62922..4eaafb2 100644
--- a/tests/daemon/face/udp.t.cpp
+++ b/tests/daemon/face/udp.t.cpp
@@ -126,7 +126,7 @@
   auto multicastFace1a = factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072");
   BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
   BOOST_CHECK_EQUAL(multicastFace1->isLocal(), false);
-  BOOST_CHECK_EQUAL(multicastFace1->isOnDemand(), false);
+  BOOST_CHECK_EQUAL(multicastFace1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
   BOOST_CHECK_EQUAL(multicastFace1->isMultiAccess(), true);
 
   //same endpoint of a multicast face
@@ -569,7 +569,7 @@
 
   limitedIo.run(1, time::milliseconds(100)); // 1 create (on channel2)
   BOOST_REQUIRE(face2 != nullptr);
-  BOOST_CHECK_EQUAL(face2->isOnDemand(), false);
+  BOOST_CHECK_EQUAL(face2->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
   BOOST_CHECK_EQUAL(face2->isMultiAccess(), false);
 
   // face2 sends to channel1, creates face1
@@ -579,7 +579,7 @@
   limitedIo.run(2, time::seconds(1)); // 1 accept (on channel1), 1 receive (on face1)
   BOOST_CHECK_EQUAL(channel1->size(), 1);
   BOOST_REQUIRE(face1 != nullptr);
-  BOOST_CHECK_EQUAL(face1->isOnDemand(), true);
+  BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
   BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);
 
   limitedIo.defer(time::seconds(1));
diff --git a/tests/daemon/face/unix-stream.t.cpp b/tests/daemon/face/unix-stream.t.cpp
index 9816729..44df52d 100644
--- a/tests/daemon/face/unix-stream.t.cpp
+++ b/tests/daemon/face/unix-stream.t.cpp
@@ -190,7 +190,7 @@
 
   BOOST_REQUIRE(static_cast<bool>(face1));
   BOOST_CHECK_EQUAL(face1->isLocal(), true);
-  BOOST_CHECK_EQUAL(face1->isOnDemand(), true);
+  BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
   BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);
   BOOST_CHECK_EQUAL(face1->getRemoteUri().getScheme(), "fd");
   BOOST_CHECK_NO_THROW(std::stoi(face1->getRemoteUri().getHost()));
diff --git a/tests/daemon/face/websocket.t.cpp b/tests/daemon/face/websocket.t.cpp
index e0472bc..7170e6c 100644
--- a/tests/daemon/face/websocket.t.cpp
+++ b/tests/daemon/face/websocket.t.cpp
@@ -236,7 +236,7 @@
 
   BOOST_REQUIRE(static_cast<bool>(face1));
   BOOST_CHECK_EQUAL(face1->isLocal(), false);
-  BOOST_CHECK_EQUAL(face1->isOnDemand(), true);
+  BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
   BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);
   BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "ws://127.0.0.1:20070");
 
diff --git a/tests/daemon/mgmt/face-query-status-publisher-common.hpp b/tests/daemon/mgmt/face-query-status-publisher-common.hpp
index a274c52..09582c9 100644
--- a/tests/daemon/mgmt/face-query-status-publisher-common.hpp
+++ b/tests/daemon/mgmt/face-query-status-publisher-common.hpp
@@ -83,12 +83,7 @@
       BOOST_CHECK_EQUAL(status.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
     }
 
-    if (reference->isOnDemand()) {
-      BOOST_CHECK_EQUAL(status.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
-    }
-    else {
-      BOOST_CHECK_EQUAL(status.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
-    }
+    BOOST_CHECK_EQUAL(status.getFacePersistency(), reference->getPersistency());
 
     if (reference->isMultiAccess()) {
       BOOST_CHECK_EQUAL(status.getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS);
diff --git a/tests/daemon/mgmt/face-query-status-publisher.t.cpp b/tests/daemon/mgmt/face-query-status-publisher.t.cpp
index 217a863..09f6804 100644
--- a/tests/daemon/mgmt/face-query-status-publisher.t.cpp
+++ b/tests/daemon/mgmt/face-query-status-publisher.t.cpp
@@ -119,7 +119,7 @@
                                                     "/localhost/nfd/FaceStatusPublisherFixture",
                                                     filter, m_keyChain);
   BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(m_dummyFace), false);
-  multicastFace->setOnDemand(true);
+  multicastFace->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
   BOOST_CHECK_EQUAL(faceQueryStatusPublisher.doesMatchFilter(multicastFace), true);
 }
 
diff --git a/tests/daemon/mgmt/face-status-publisher-common.hpp b/tests/daemon/mgmt/face-status-publisher-common.hpp
index 11f4913..d785149 100644
--- a/tests/daemon/mgmt/face-status-publisher-common.hpp
+++ b/tests/daemon/mgmt/face-status-publisher-common.hpp
@@ -142,12 +142,7 @@
       BOOST_CHECK_EQUAL(status.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
     }
 
-    if (reference->isOnDemand()) {
-      BOOST_CHECK_EQUAL(status.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
-    }
-    else {
-      BOOST_CHECK_EQUAL(status.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
-    }
+    BOOST_CHECK_EQUAL(status.getFacePersistency(), reference->getPersistency());
 
     if (reference->isMultiAccess()) {
       BOOST_CHECK_EQUAL(status.getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS);