face: Transport::canChangePersistencyTo

Feasibility of transport persistency change can be checked with
Transport::canChangePersistencyTo before executing the actual change.
This enables management to verify persistency and other parameters
in a faces/update command before applying the updates.

Change-Id: Ia283f0daf678f47aad7b78b7e06dee4827f57cab
refs: #3232
diff --git a/daemon/face/transport.cpp b/daemon/face/transport.cpp
index 26cc0d7..81f6edf 100644
--- a/daemon/face/transport.cpp
+++ b/daemon/face/transport.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -127,23 +127,47 @@
   m_service->receivePacket(std::move(packet));
 }
 
+bool
+Transport::canChangePersistencyTo(ndn::nfd::FacePersistency newPersistency) const
+{
+  // not changing, or setting initial persistency in subclass constructor
+  if (m_persistency == newPersistency || m_persistency == ndn::nfd::FACE_PERSISTENCY_NONE) {
+    return true;
+  }
+
+  if (newPersistency == ndn::nfd::FACE_PERSISTENCY_NONE) {
+    NFD_LOG_FACE_TRACE("cannot change persistency to NONE");
+    return false;
+  }
+
+  return this->canChangePersistencyToImpl(newPersistency);
+}
+
+bool
+Transport::canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const
+{
+  return false;
+}
+
 void
 Transport::setPersistency(ndn::nfd::FacePersistency newPersistency)
 {
+  BOOST_ASSERT(canChangePersistencyTo(newPersistency));
+
   if (m_persistency == newPersistency) {
     return;
   }
 
-  if (newPersistency == ndn::nfd::FACE_PERSISTENCY_NONE) {
-    throw std::runtime_error("invalid persistency transition");
-  }
+  NFD_LOG_FACE_INFO("setPersistency " << m_persistency << " -> " << newPersistency);
 
-  if (m_persistency != ndn::nfd::FACE_PERSISTENCY_NONE) {
-    this->beforeChangePersistency(newPersistency);
-    NFD_LOG_FACE_DEBUG("setPersistency " << m_persistency << " -> " << newPersistency);
-  }
-
+  auto oldPersistency = m_persistency;
   m_persistency = newPersistency;
+  this->afterChangePersistency(oldPersistency);
+}
+
+void
+Transport::afterChangePersistency(ndn::nfd::FacePersistency oldPersistency)
+{
 }
 
 void