mgmt: make congestion marking parameters optional

refs #4465

Change-Id: I5ab07ecd4f1b7f4c948ba359513e65ac2e96c943
diff --git a/src/mgmt/nfd/face-status.cpp b/src/mgmt/nfd/face-status.cpp
index 0a284cd..0c127ae 100644
--- a/src/mgmt/nfd/face-status.cpp
+++ b/src/mgmt/nfd/face-status.cpp
@@ -32,9 +32,7 @@
 BOOST_CONCEPT_ASSERT((StatusDatasetItem<FaceStatus>));
 
 FaceStatus::FaceStatus()
-  : m_baseCongestionMarkingInterval(0)
-  , m_defaultCongestionThreshold(0)
-  , m_nInInterests(0)
+  : m_nInInterests(0)
   , m_nInData(0)
   , m_nInNacks(0)
   , m_nOutInterests(0)
@@ -65,10 +63,14 @@
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInNacks, m_nInNacks);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInData, m_nInData);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInInterests, m_nInInterests);
-  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::DefaultCongestionThreshold,
-                                                m_defaultCongestionThreshold);
-  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::BaseCongestionMarkingInterval,
-                                                m_baseCongestionMarkingInterval.count());
+  if (m_defaultCongestionThreshold) {
+    totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::DefaultCongestionThreshold,
+                                                  *m_defaultCongestionThreshold);
+  }
+  if (m_baseCongestionMarkingInterval) {
+    totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::BaseCongestionMarkingInterval,
+                                                  m_baseCongestionMarkingInterval->count());
+  }
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::LinkType, m_linkType);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::FacePersistency, m_facePersistency);
   totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::FaceScope, m_faceScope);
@@ -170,11 +172,11 @@
   }
 
   if (val != m_wire.elements_end() && val->type() == tlv::nfd::BaseCongestionMarkingInterval) {
-    m_baseCongestionMarkingInterval = time::nanoseconds(readNonNegativeInteger(*val));
+    m_baseCongestionMarkingInterval.emplace(readNonNegativeInteger(*val));
     ++val;
   }
   else {
-    BOOST_THROW_EXCEPTION(Error("missing required BaseCongestionMarkingInterval field"));
+    m_baseCongestionMarkingInterval = nullopt;
   }
 
   if (val != m_wire.elements_end() && val->type() == tlv::nfd::DefaultCongestionThreshold) {
@@ -182,7 +184,7 @@
     ++val;
   }
   else {
-    BOOST_THROW_EXCEPTION(Error("missing required DefaultCongestionThreshold field"));
+    m_defaultCongestionThreshold = nullopt;
   }
 
   if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) {
@@ -283,6 +285,14 @@
 }
 
 FaceStatus&
+FaceStatus::unsetBaseCongestionMarkingInterval()
+{
+  m_wire.reset();
+  m_baseCongestionMarkingInterval = nullopt;
+  return *this;
+}
+
+FaceStatus&
 FaceStatus::setDefaultCongestionThreshold(uint64_t threshold)
 {
   m_wire.reset();
@@ -291,6 +301,14 @@
 }
 
 FaceStatus&
+FaceStatus::unsetDefaultCongestionThreshold()
+{
+  m_wire.reset();
+  m_defaultCongestionThreshold = nullopt;
+  return *this;
+}
+
+FaceStatus&
 FaceStatus::setNInInterests(uint64_t nInInterests)
 {
   m_wire.reset();
@@ -366,8 +384,12 @@
       a.getFlags() == b.getFlags() &&
       a.hasExpirationPeriod() == b.hasExpirationPeriod() &&
       (!a.hasExpirationPeriod() || a.getExpirationPeriod() == b.getExpirationPeriod()) &&
-      a.getBaseCongestionMarkingInterval() == b.getBaseCongestionMarkingInterval() &&
-      a.getDefaultCongestionThreshold() == b.getDefaultCongestionThreshold() &&
+      a.hasBaseCongestionMarkingInterval() == b.hasBaseCongestionMarkingInterval() &&
+      (!a.hasBaseCongestionMarkingInterval() ||
+       a.getBaseCongestionMarkingInterval() == b.getBaseCongestionMarkingInterval()) &&
+      a.hasDefaultCongestionThreshold() == b.hasDefaultCongestionThreshold() &&
+      (!a.hasDefaultCongestionThreshold() ||
+       a.getDefaultCongestionThreshold() == b.getDefaultCongestionThreshold()) &&
       a.getNInInterests() == b.getNInInterests() &&
       a.getNInData() == b.getNInData() &&
       a.getNInNacks() == b.getNInNacks() &&
@@ -394,10 +416,17 @@
 
   os << "     FaceScope: " << status.getFaceScope() << ",\n"
      << "     FacePersistency: " << status.getFacePersistency() << ",\n"
-     << "     LinkType: " << status.getLinkType() << ",\n"
-     << "     BaseCongestionMarkingInterval: " << status.getBaseCongestionMarkingInterval() << ",\n"
-     << "     DefaultCongestionThreshold: " << status.getDefaultCongestionThreshold() << " bytes,\n"
-     << "     Flags: " << AsHex{status.getFlags()} << ",\n"
+     << "     LinkType: " << status.getLinkType() << ",\n";
+
+  if (status.hasBaseCongestionMarkingInterval()) {
+    os << "     BaseCongestionMarkingInterval: " << status.getBaseCongestionMarkingInterval() << ",\n";
+  }
+
+  if (status.hasDefaultCongestionThreshold()) {
+    os << "     DefaultCongestionThreshold: " << status.getDefaultCongestionThreshold() << " bytes,\n";
+  }
+
+  os << "     Flags: " << AsHex{status.getFlags()} << ",\n"
      << "     Counters: {Interests: {in: " << status.getNInInterests() << ", "
      << "out: " << status.getNOutInterests() << "},\n"
      << "                Data: {in: " << status.getNInData() << ", "