util: ignore NextHopFaceId on Nack in DummyClientFace

refs #4224

Change-Id: Ic2e78eabc83fbeeea8283412c44b10a04c3acd86
diff --git a/src/detail/lp-field-tag.hpp b/src/detail/lp-field-tag.hpp
index f8b2aa5..5c01f58 100644
--- a/src/detail/lp-field-tag.hpp
+++ b/src/detail/lp-field-tag.hpp
@@ -37,6 +37,15 @@
   }
 }
 
+template<typename Tag, typename Field, typename Packet>
+void
+addTagFromField(Packet& packet, const lp::Packet& lpPacket)
+{
+  if (lpPacket.has<Field>()) {
+    packet.setTag(make_shared<Tag>(lpPacket.get<Field>()));
+  }
+}
+
 } // namespace ndn
 
 #endif // NDN_DETAIL_LP_FIELD_TAG_HPP
diff --git a/src/face.cpp b/src/face.cpp
index 8e59ce9..8580720 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -376,13 +376,8 @@
 static void
 extractLpLocalFields(NetPkt& netPacket, const lp::Packet& lpPacket)
 {
-  if (lpPacket.has<lp::IncomingFaceIdField>()) {
-    netPacket.setTag(make_shared<lp::IncomingFaceIdTag>(lpPacket.get<lp::IncomingFaceIdField>()));
-  }
-
-  if (lpPacket.has<lp::CongestionMarkField>()) {
-    netPacket.setTag(make_shared<lp::CongestionMarkTag>(lpPacket.get<lp::CongestionMarkField>()));
-  }
+  addTagFromField<lp::IncomingFaceIdTag, lp::IncomingFaceIdField>(netPacket, lpPacket);
+  addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(netPacket, lpPacket);
 }
 
 void
diff --git a/src/util/dummy-client-face.cpp b/src/util/dummy-client-face.cpp
index 57a43b7..989b455 100644
--- a/src/util/dummy-client-face.cpp
+++ b/src/util/dummy-client-face.cpp
@@ -135,34 +135,19 @@
       if (lpPacket.has<lp::NackField>()) {
         shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(std::move(*interest));
         nack->setHeader(lpPacket.get<lp::NackField>());
-        if (lpPacket.has<lp::NextHopFaceIdField>()) {
-          nack->setTag(make_shared<lp::NextHopFaceIdTag>(lpPacket.get<lp::NextHopFaceIdField>()));
-        }
-        if (lpPacket.has<lp::CongestionMarkField>()) {
-          nack->setTag(make_shared<lp::CongestionMarkTag>(lpPacket.get<lp::CongestionMarkField>()));
-        }
+        addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*nack, lpPacket);
         onSendNack(*nack);
       }
       else {
-        if (lpPacket.has<lp::NextHopFaceIdField>()) {
-          interest->setTag(make_shared<lp::NextHopFaceIdTag>(lpPacket.get<lp::NextHopFaceIdField>()));
-        }
-        if (lpPacket.has<lp::CongestionMarkField>()) {
-          interest->setTag(make_shared<lp::CongestionMarkTag>(lpPacket.get<lp::CongestionMarkField>()));
-        }
+        addTagFromField<lp::NextHopFaceIdTag, lp::NextHopFaceIdField>(*interest, lpPacket);
+        addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*interest, lpPacket);
         onSendInterest(*interest);
       }
     }
     else if (block.type() == tlv::Data) {
       shared_ptr<Data> data = make_shared<Data>(block);
-
-      if (lpPacket.has<lp::CachePolicyField>()) {
-        data->setTag(make_shared<lp::CachePolicyTag>(lpPacket.get<lp::CachePolicyField>()));
-      }
-      if (lpPacket.has<lp::CongestionMarkField>()) {
-        data->setTag(make_shared<lp::CongestionMarkTag>(lpPacket.get<lp::CongestionMarkField>()));
-      }
-
+      addTagFromField<lp::CachePolicyTag, lp::CachePolicyField>(*data, lpPacket);
+      addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*data, lpPacket);
       onSendData(*data);
     }
   });