tools: add mtu option to 'nfdc face create'

refs #4789

Change-Id: I9e31c5fb460ee99199332ffb6fadc9f0f33125e9
diff --git a/tools/nfd-status-http-server-files/nfd-status.xsl b/tools/nfd-status-http-server-files/nfd-status.xsl
index 725e53e..d9a996c 100644
--- a/tools/nfd-status-http-server-files/nfd-status.xsl
+++ b/tools/nfd-status-http-server-files/nfd-status.xsl
@@ -165,6 +165,7 @@
         <th>Scope</th>
         <th>Persistency</th>
         <th>LinkType</th>
+        <th>MTU</th>
         <th>Flags</th>
         <th>Expires in</th>
         <th>In Interests</th>
@@ -187,6 +188,16 @@
         <td><xsl:value-of select="nfd:facePersistency"/></td>
         <td><xsl:value-of select="nfd:linkType"/></td>
         <td>
+          <xsl:choose>
+            <xsl:when test="nfd:mtu">
+              <xsl:value-of select="nfd:mtu"/>
+            </xsl:when>
+            <xsl:otherwise>
+              n/a
+            </xsl:otherwise>
+          </xsl:choose>
+        </td>
+        <td>
           <xsl:if test="nfd:flags/nfd:localFieldsEnabled">local-fields </xsl:if>
           <xsl:if test="nfd:flags/nfd:lpReliabilityEnabled">reliability </xsl:if>
           <xsl:if test="nfd:flags/nfd:congestionMarkingEnabled">congestion-marking </xsl:if>
diff --git a/tools/nfdc/face-module.cpp b/tools/nfdc/face-module.cpp
index 23a03db..ae6ba16 100644
--- a/tools/nfdc/face-module.cpp
+++ b/tools/nfdc/face-module.cpp
@@ -57,7 +57,8 @@
     .addArg("reliability", ArgValueType::BOOLEAN, Required::NO, Positional::NO)
     .addArg("congestion-marking", ArgValueType::BOOLEAN, Required::NO, Positional::NO)
     .addArg("congestion-marking-interval", ArgValueType::UNSIGNED, Required::NO, Positional::NO)
-    .addArg("default-congestion-threshold", ArgValueType::UNSIGNED, Required::NO, Positional::NO);
+    .addArg("default-congestion-threshold", ArgValueType::UNSIGNED, Required::NO, Positional::NO)
+    .addArg("mtu", ArgValueType::UNSIGNED, Required::NO, Positional::NO);
   parser.addCommand(defFaceCreate, &FaceModule::create);
 
   CommandDefinition defFaceDestroy("face", "destroy");
@@ -159,6 +160,7 @@
   auto congestionMarking = ctx.args.getTribool("congestion-marking");
   auto baseCongestionMarkingIntervalMs = ctx.args.getOptional<uint64_t>("congestion-marking-interval");
   auto defaultCongestionThreshold = ctx.args.getOptional<uint64_t>("default-congestion-threshold");
+  auto mtu = ctx.args.getOptional<uint64_t>("mtu");
 
   FaceUri canonicalRemote;
   optional<FaceUri> canonicalLocal;
@@ -192,7 +194,11 @@
       return false;
     }
 
-    if (persistencyLessThan(respParams.getFacePersistency(), persistency)) {
+    if (mtu && (!respParams.hasMtu() || respParams.getMtu() != *mtu)) {
+      // Mtu cannot be changed with faces/update
+      return false;
+    }
+    else if (persistencyLessThan(respParams.getFacePersistency(), persistency)) {
       // need to upgrade persistency
       ControlParameters params;
       params.setFaceId(respParams.getFaceId()).setFacePersistency(persistency);
@@ -263,6 +269,9 @@
     if (defaultCongestionThreshold) {
       params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
     }
+    if (mtu) {
+      params.setMtu(*mtu);
+    }
 
     ctx.controller.start<ndn::nfd::FaceCreateCommand>(
       params,
@@ -400,6 +409,10 @@
     os << "</congestion>";
   }
 
+  if (item.hasMtu()) {
+    os << "<mtu>" << item.getMtu() << "</mtu>";
+  }
+
   if (item.getFlags() == 0) {
     os << "<flags/>";
   }
@@ -469,6 +482,10 @@
     os << "}";
   }
 
+  if (item.hasMtu()) {
+    os << ia("mtu") << item.getMtu();
+  }
+
   os << ia("counters")
      << "{in={"
      << item.getNInInterests() << "i "
@@ -512,6 +529,9 @@
   if (resp.hasDefaultCongestionThreshold()) {
     os << ia("default-congestion-threshold") << resp.getDefaultCongestionThreshold() << "B";
   }
+  if (resp.hasMtu()) {
+    os << ia("mtu") << resp.getMtu();
+  }
   os << '\n';
 }