face: GenericLinkService encodes and decodes CongestionMark field

refs #3797

Change-Id: Ia6b00a36f3e7ed9ec98e41dee7e2f97eaf235ddd
diff --git a/daemon/face/generic-link-service.cpp b/daemon/face/generic-link-service.cpp
index a922cbe..2a7f527 100644
--- a/daemon/face/generic-link-service.cpp
+++ b/daemon/face/generic-link-service.cpp
@@ -58,9 +58,7 @@
 {
   lp::Packet lpPacket(interest.wireEncode());
 
-  if (m_options.allowLocalFields) {
-    encodeLocalFields(interest, lpPacket);
-  }
+  encodeLpFields(interest, lpPacket);
 
   this->sendNetPacket(std::move(lpPacket));
 }
@@ -70,9 +68,7 @@
 {
   lp::Packet lpPacket(data.wireEncode());
 
-  if (m_options.allowLocalFields) {
-    encodeLocalFields(data, lpPacket);
-  }
+  encodeLpFields(data, lpPacket);
 
   this->sendNetPacket(std::move(lpPacket));
 }
@@ -83,19 +79,24 @@
   lp::Packet lpPacket(nack.getInterest().wireEncode());
   lpPacket.add<lp::NackField>(nack.getHeader());
 
-  if (m_options.allowLocalFields) {
-    encodeLocalFields(nack, lpPacket);
-  }
+  encodeLpFields(nack, lpPacket);
 
   this->sendNetPacket(std::move(lpPacket));
 }
 
 void
-GenericLinkService::encodeLocalFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket)
+GenericLinkService::encodeLpFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket)
 {
-  shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
-  if (incomingFaceIdTag != nullptr) {
-    lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
+  if (m_options.allowLocalFields) {
+    shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
+    if (incomingFaceIdTag != nullptr) {
+      lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
+    }
+  }
+
+  shared_ptr<lp::CongestionMarkTag> congestionMarkTag = netPkt.getTag<lp::CongestionMarkTag>();
+  if (congestionMarkTag != nullptr) {
+    lpPacket.add<lp::CongestionMarkField>(*congestionMarkTag);
   }
 }
 
@@ -241,6 +242,10 @@
     NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
   }
 
+  if (firstPkt.has<lp::CongestionMarkField>()) {
+    interest->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
+  }
+
   this->receiveInterest(*interest);
 }
 
@@ -279,6 +284,10 @@
     NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
   }
 
+  if (firstPkt.has<lp::CongestionMarkField>()) {
+    data->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
+  }
+
   this->receiveData(*data);
 }
 
@@ -307,6 +316,10 @@
     NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
   }
 
+  if (firstPkt.has<lp::CongestionMarkField>()) {
+    nack.setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
+  }
+
   this->receiveNack(nack);
 }