face: use IncomingFaceId, NextHopFaceId, CachePolicy tags
This commit replaces all LocalControlHeader usages with these tags,
and deletes LocalFace.
This commit also does minor improvements in RIB test suites.
refs #3339
Change-Id: I14cbfc296a6723a5860bf8bd95d9804d3bac3da5
diff --git a/daemon/face/generic-link-service.cpp b/daemon/face/generic-link-service.cpp
index d6d6c02..d1536ce 100644
--- a/daemon/face/generic-link-service.cpp
+++ b/daemon/face/generic-link-service.cpp
@@ -49,29 +49,31 @@
, m_reassembler(m_options.reassemblerOptions, this)
, m_lastSeqNo(-2)
{
- m_reassembler.beforeTimeout.connect(bind([this] { ++nReassemblyTimeouts; }));
+ m_reassembler.beforeTimeout.connect(bind([this] { ++this->nReassemblyTimeouts; }));
}
void
GenericLinkService::doSendInterest(const Interest& interest)
{
lp::Packet lpPacket(interest.wireEncode());
+
if (m_options.allowLocalFields) {
encodeLocalFields(interest, lpPacket);
}
- sendNetPacket(std::move(lpPacket));
+ this->sendNetPacket(std::move(lpPacket));
}
void
GenericLinkService::doSendData(const Data& data)
{
lp::Packet lpPacket(data.wireEncode());
+
if (m_options.allowLocalFields) {
encodeLocalFields(data, lpPacket);
}
- sendNetPacket(std::move(lpPacket));
+ this->sendNetPacket(std::move(lpPacket));
}
void
@@ -79,50 +81,21 @@
{
lp::Packet lpPacket(nack.getInterest().wireEncode());
lpPacket.add<lp::NackField>(nack.getHeader());
+
if (m_options.allowLocalFields) {
- encodeLocalFields(nack.getInterest(), lpPacket);
+ encodeLocalFields(nack, lpPacket);
}
- sendNetPacket(std::move(lpPacket));
+ this->sendNetPacket(std::move(lpPacket));
}
-bool
-GenericLinkService::encodeLocalFields(const Interest& interest, lp::Packet& lpPacket)
+void
+GenericLinkService::encodeLocalFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket)
{
- if (interest.getLocalControlHeader().hasIncomingFaceId()) {
- lpPacket.add<lp::IncomingFaceIdField>(interest.getIncomingFaceId());
+ shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
+ if (incomingFaceIdTag != nullptr) {
+ lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
}
-
- if (interest.getLocalControlHeader().hasCachingPolicy()) {
- // Packet must be dropped
- return false;
- }
-
- return true;
-}
-
-bool
-GenericLinkService::encodeLocalFields(const Data& data, lp::Packet& lpPacket)
-{
- if (data.getLocalControlHeader().hasIncomingFaceId()) {
- lpPacket.add<lp::IncomingFaceIdField>(data.getIncomingFaceId());
- }
-
- if (data.getLocalControlHeader().hasCachingPolicy()) {
- switch (data.getCachingPolicy()) {
- case ndn::nfd::LocalControlHeader::CachingPolicy::NO_CACHE: {
- lp::CachePolicy cachePolicy;
- cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE);
- lpPacket.add<lp::CachePolicyField>(cachePolicy);
- break;
- }
- default: {
- break;
- }
- }
- }
-
- return true;
}
void
@@ -135,7 +108,7 @@
std::tie(isOk, frags) = m_fragmenter.fragmentPacket(pkt, mtu);
if (!isOk) {
// fragmentation failed (warning is logged by LpFragmenter)
- ++nFragmentationErrors;
+ ++this->nFragmentationErrors;
return;
}
}
@@ -145,7 +118,7 @@
if (frags.size() > 1) {
// sequence is needed only if packet is fragmented
- assignSequences(frags);
+ this->assignSequences(frags);
}
else {
// even if indexed fragmentation is enabled, the fragmenter should not
@@ -158,11 +131,11 @@
for (const lp::Packet& frag : frags) {
Transport::Packet tp(frag.wireEncode());
if (mtu != MTU_UNLIMITED && tp.packet.size() > static_cast<size_t>(mtu)) {
- ++nOutOverMtu;
+ ++this->nOutOverMtu;
NFD_LOG_FACE_WARN("attempt to send packet over MTU limit");
continue;
}
- sendPacket(std::move(tp));
+ this->sendPacket(std::move(tp));
}
}
@@ -249,7 +222,7 @@
if (firstPkt.has<lp::NextHopFaceIdField>()) {
if (m_options.allowLocalFields) {
- interest->setNextHopFaceId(firstPkt.get<lp::NextHopFaceIdField>());
+ interest->setTag(make_shared<lp::NextHopFaceIdTag>(firstPkt.get<lp::NextHopFaceIdField>()));
}
else {
NFD_LOG_FACE_WARN("received NextHopFaceId, but local fields disabled: DROP");
@@ -292,16 +265,9 @@
if (firstPkt.has<lp::CachePolicyField>()) {
if (m_options.allowLocalFields) {
- lp::CachePolicyType policy = firstPkt.get<lp::CachePolicyField>().getPolicy();
- switch (policy) {
- case lp::CachePolicyType::NO_CACHE:
- data->setCachingPolicy(ndn::nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
- break;
- default:
- ++this->nInNetInvalid;
- NFD_LOG_FACE_WARN("unrecognized CachePolicyType " << policy << ": DROP");
- return;
- }
+ // In case of an invalid CachePolicyType, get<lp::CachePolicyField> will throw,
+ // so it's unnecessary to check here.
+ data->setTag(make_shared<lp::CachePolicyTag>(firstPkt.get<lp::CachePolicyField>()));
}
else {
NFD_LOG_FACE_WARN("received CachePolicy, but local fields disabled: IGNORE");