blob: a2c85414f89a11ed729829a5236574dd66baf662 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry7b0071e2017-07-03 17:33:31 +00002/*
Davide Pesaventoa8098582019-03-31 15:48:02 -04003 * Copyright (c) 2014-2019, Regents of the University of California,
Eric Newberrya98bf932015-09-21 00:58:47 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "generic-link-service.hpp"
Eric Newberryb49313d2017-12-24 20:22:27 -070027
Junxiao Shicbc8e942016-09-06 03:17:45 +000028#include <ndn-cxx/lp/tags.hpp>
Eric Newberrya98bf932015-09-21 00:58:47 -070029
Eric Newberryb49313d2017-12-24 20:22:27 -070030#include <cmath>
31
Eric Newberrya98bf932015-09-21 00:58:47 -070032namespace nfd {
33namespace face {
34
Davide Pesaventoa3148082018-04-12 18:21:54 -040035NFD_LOG_INIT(GenericLinkService);
Eric Newberrya98bf932015-09-21 00:58:47 -070036
Davide Pesaventoa8098582019-03-31 15:48:02 -040037constexpr size_t CONGESTION_MARK_SIZE = tlv::sizeOfVarNumber(lp::tlv::CongestionMark) + // type
38 tlv::sizeOfVarNumber(sizeof(uint64_t)) + // length
39 tlv::sizeOfNonNegativeInteger(UINT64_MAX); // value
40
Eric Newberryb49313d2017-12-24 20:22:27 -070041constexpr uint32_t DEFAULT_CONGESTION_THRESHOLD_DIVISOR = 2;
42
Eric Newberry86d31872015-09-23 16:24:59 -070043GenericLinkService::GenericLinkService(const GenericLinkService::Options& options)
Eric Newberry73bcad32017-04-25 17:57:35 -070044 : m_options(options)
Eric Newberry4c3e6b82015-11-10 16:48:42 -070045 , m_fragmenter(m_options.fragmenterOptions, this)
46 , m_reassembler(m_options.reassemblerOptions, this)
Eric Newberry185ab292017-03-28 06:45:39 +000047 , m_reliability(m_options.reliabilityOptions, this)
Eric Newberry4c3e6b82015-11-10 16:48:42 -070048 , m_lastSeqNo(-2)
Eric Newberryb49313d2017-12-24 20:22:27 -070049 , m_nextMarkTime(time::steady_clock::TimePoint::max())
50 , m_lastMarkTime(time::steady_clock::TimePoint::min())
51 , m_nMarkedSinceInMarkingState(0)
Eric Newberry86d31872015-09-23 16:24:59 -070052{
Davide Pesaventoe4b22382018-06-10 14:37:24 -040053 m_reassembler.beforeTimeout.connect([this] (auto...) { ++this->nReassemblyTimeouts; });
54 m_reliability.onDroppedInterest.connect([this] (const auto& i) { this->notifyDroppedInterest(i); });
Eric Newberry73bcad32017-04-25 17:57:35 -070055 nReassembling.observe(&m_reassembler);
Eric Newberry86d31872015-09-23 16:24:59 -070056}
57
Eric Newberrya98bf932015-09-21 00:58:47 -070058void
Eric Newberry185ab292017-03-28 06:45:39 +000059GenericLinkService::setOptions(const GenericLinkService::Options& options)
60{
61 m_options = options;
62 m_fragmenter.setOptions(m_options.fragmenterOptions);
63 m_reassembler.setOptions(m_options.reassemblerOptions);
64 m_reliability.setOptions(m_options.reliabilityOptions);
65}
66
67void
68GenericLinkService::requestIdlePacket()
69{
70 // No need to request Acks to attach to this packet from LpReliability, as they are already
71 // attached in sendLpPacket
72 this->sendLpPacket({});
73}
74
75void
76GenericLinkService::sendLpPacket(lp::Packet&& pkt)
77{
78 const ssize_t mtu = this->getTransport()->getMtu();
Eric Newberryb49313d2017-12-24 20:22:27 -070079
Eric Newberry185ab292017-03-28 06:45:39 +000080 if (m_options.reliabilityOptions.isEnabled) {
81 m_reliability.piggyback(pkt, mtu);
82 }
83
Eric Newberryb49313d2017-12-24 20:22:27 -070084 if (m_options.allowCongestionMarking) {
85 checkCongestionLevel(pkt);
86 }
87
Eric Newberry185ab292017-03-28 06:45:39 +000088 Transport::Packet tp(pkt.wireEncode());
89 if (mtu != MTU_UNLIMITED && tp.packet.size() > static_cast<size_t>(mtu)) {
90 ++this->nOutOverMtu;
91 NFD_LOG_FACE_WARN("attempted to send packet over MTU limit");
92 return;
93 }
94 this->sendPacket(std::move(tp));
95}
96
97void
Eric Newberrya98bf932015-09-21 00:58:47 -070098GenericLinkService::doSendInterest(const Interest& interest)
99{
100 lp::Packet lpPacket(interest.wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000101
Eric Newberryee400b52016-11-24 14:12:48 +0000102 encodeLpFields(interest, lpPacket);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700103
Eric Newberry41aba102017-11-01 16:42:13 -0700104 this->sendNetPacket(std::move(lpPacket), true);
Eric Newberrya98bf932015-09-21 00:58:47 -0700105}
106
107void
108GenericLinkService::doSendData(const Data& data)
109{
110 lp::Packet lpPacket(data.wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000111
Eric Newberryee400b52016-11-24 14:12:48 +0000112 encodeLpFields(data, lpPacket);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700113
Eric Newberry41aba102017-11-01 16:42:13 -0700114 this->sendNetPacket(std::move(lpPacket), false);
Eric Newberrya98bf932015-09-21 00:58:47 -0700115}
116
117void
118GenericLinkService::doSendNack(const lp::Nack& nack)
119{
120 lp::Packet lpPacket(nack.getInterest().wireEncode());
121 lpPacket.add<lp::NackField>(nack.getHeader());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000122
Eric Newberryee400b52016-11-24 14:12:48 +0000123 encodeLpFields(nack, lpPacket);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700124
Eric Newberry41aba102017-11-01 16:42:13 -0700125 this->sendNetPacket(std::move(lpPacket), false);
Eric Newberrya98bf932015-09-21 00:58:47 -0700126}
127
Junxiao Shi0de23a22015-12-03 20:07:02 +0000128void
Eric Newberry41aba102017-11-01 16:42:13 -0700129GenericLinkService::encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket)
Eric Newberry86d31872015-09-23 16:24:59 -0700130{
Eric Newberryee400b52016-11-24 14:12:48 +0000131 if (m_options.allowLocalFields) {
132 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
133 if (incomingFaceIdTag != nullptr) {
134 lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
135 }
136 }
137
138 shared_ptr<lp::CongestionMarkTag> congestionMarkTag = netPkt.getTag<lp::CongestionMarkTag>();
139 if (congestionMarkTag != nullptr) {
140 lpPacket.add<lp::CongestionMarkField>(*congestionMarkTag);
Eric Newberry86d31872015-09-23 16:24:59 -0700141 }
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700142
143 if (m_options.allowSelfLearning) {
144 shared_ptr<lp::NonDiscoveryTag> nonDiscoveryTag = netPkt.getTag<lp::NonDiscoveryTag>();
145 if (nonDiscoveryTag != nullptr) {
146 lpPacket.add<lp::NonDiscoveryField>(*nonDiscoveryTag);
147 }
148
149 shared_ptr<lp::PrefixAnnouncementTag> prefixAnnouncementTag = netPkt.getTag<lp::PrefixAnnouncementTag>();
150 if (prefixAnnouncementTag != nullptr) {
151 lpPacket.add<lp::PrefixAnnouncementField>(*prefixAnnouncementTag);
152 }
153 }
Spyridon Mastorakis75c03e32016-12-06 15:20:19 -0800154
155 shared_ptr<lp::HopCountTag> hopCountTag = netPkt.getTag<lp::HopCountTag>();
156 if (hopCountTag != nullptr) {
157 lpPacket.add<lp::HopCountTagField>(*hopCountTag);
158 }
159 else {
160 lpPacket.add<lp::HopCountTagField>(0);
161 }
Eric Newberry86d31872015-09-23 16:24:59 -0700162}
163
Eric Newberrya98bf932015-09-21 00:58:47 -0700164void
Eric Newberry41aba102017-11-01 16:42:13 -0700165GenericLinkService::sendNetPacket(lp::Packet&& pkt, bool isInterest)
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700166{
167 std::vector<lp::Packet> frags;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000168 ssize_t mtu = this->getTransport()->getMtu();
169
170 // Make space for feature fields in fragments
171 if (m_options.reliabilityOptions.isEnabled && mtu != MTU_UNLIMITED) {
172 mtu -= LpReliability::RESERVED_HEADER_SPACE;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000173 }
174
Eric Newberryb49313d2017-12-24 20:22:27 -0700175 if (m_options.allowCongestionMarking && mtu != MTU_UNLIMITED) {
176 mtu -= CONGESTION_MARK_SIZE;
177 }
178
179 BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0);
180
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700181 if (m_options.allowFragmentation && mtu != MTU_UNLIMITED) {
182 bool isOk = false;
183 std::tie(isOk, frags) = m_fragmenter.fragmentPacket(pkt, mtu);
184 if (!isOk) {
185 // fragmentation failed (warning is logged by LpFragmenter)
Junxiao Shi0de23a22015-12-03 20:07:02 +0000186 ++this->nFragmentationErrors;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700187 return;
188 }
189 }
190 else {
Eric Newberry41aba102017-11-01 16:42:13 -0700191 if (m_options.reliabilityOptions.isEnabled) {
192 frags.push_back(pkt);
193 }
194 else {
195 frags.push_back(std::move(pkt));
196 }
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700197 }
198
Eric Newberry185ab292017-03-28 06:45:39 +0000199 if (frags.size() == 1) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700200 // even if indexed fragmentation is enabled, the fragmenter should not
201 // fragment the packet if it can fit in MTU
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700202 BOOST_ASSERT(!frags.front().has<lp::FragIndexField>());
203 BOOST_ASSERT(!frags.front().has<lp::FragCountField>());
204 }
205
Eric Newberry7b0071e2017-07-03 17:33:31 +0000206 // Only assign sequences to fragments if packet contains more than 1 fragment
207 if (frags.size() > 1) {
Eric Newberry185ab292017-03-28 06:45:39 +0000208 // Assign sequences to all fragments
209 this->assignSequences(frags);
210 }
211
212 if (m_options.reliabilityOptions.isEnabled && frags.front().has<lp::FragmentField>()) {
Eric Newberry41aba102017-11-01 16:42:13 -0700213 m_reliability.handleOutgoing(frags, std::move(pkt), isInterest);
Eric Newberry185ab292017-03-28 06:45:39 +0000214 }
215
216 for (lp::Packet& frag : frags) {
217 this->sendLpPacket(std::move(frag));
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700218 }
219}
220
221void
222GenericLinkService::assignSequence(lp::Packet& pkt)
223{
224 pkt.set<lp::SequenceField>(++m_lastSeqNo);
225}
226
227void
228GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts)
229{
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400230 std::for_each(pkts.begin(), pkts.end(), [this] (auto& pkt) { this->assignSequence(pkt); });
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700231}
232
233void
Eric Newberryb49313d2017-12-24 20:22:27 -0700234GenericLinkService::checkCongestionLevel(lp::Packet& pkt)
235{
236 ssize_t sendQueueLength = getTransport()->getSendQueueLength();
237 // This operation requires that the transport supports retrieving current send queue length
238 if (sendQueueLength < 0) {
239 return;
240 }
241
242 // To avoid overflowing the queue, set the congestion threshold to at least half of the send
243 // queue capacity.
244 size_t congestionThreshold = m_options.defaultCongestionThreshold;
245 if (getTransport()->getSendQueueCapacity() >= 0) {
246 congestionThreshold = std::min(congestionThreshold,
247 static_cast<size_t>(getTransport()->getSendQueueCapacity()) /
248 DEFAULT_CONGESTION_THRESHOLD_DIVISOR);
249 }
250
251 if (sendQueueLength > 0) {
252 NFD_LOG_FACE_TRACE("txqlen=" << sendQueueLength << " threshold=" << congestionThreshold <<
253 " capacity=" << getTransport()->getSendQueueCapacity());
254 }
255
256 if (static_cast<size_t>(sendQueueLength) > congestionThreshold) { // Send queue is congested
257 const auto now = time::steady_clock::now();
258 if (now >= m_nextMarkTime || now >= m_lastMarkTime + m_options.baseCongestionMarkingInterval) {
259 // Mark at most one initial packet per baseCongestionMarkingInterval
260 if (m_nMarkedSinceInMarkingState == 0) {
261 m_nextMarkTime = now;
262 }
263
264 // Time to mark packet
265 pkt.set<lp::CongestionMarkField>(1);
266 ++nCongestionMarked;
267 NFD_LOG_FACE_DEBUG("LpPacket was marked as congested");
268
269 ++m_nMarkedSinceInMarkingState;
270 // Decrease the marking interval by the inverse of the square root of the number of packets
271 // marked in this incident of congestion
272 m_nextMarkTime += time::nanoseconds(static_cast<time::nanoseconds::rep>(
273 m_options.baseCongestionMarkingInterval.count() /
274 std::sqrt(m_nMarkedSinceInMarkingState)));
275 m_lastMarkTime = now;
276 }
277 }
278 else if (m_nextMarkTime != time::steady_clock::TimePoint::max()) {
279 // Congestion incident has ended, so reset
280 NFD_LOG_FACE_DEBUG("Send queue length dropped below congestion threshold");
281 m_nextMarkTime = time::steady_clock::TimePoint::max();
282 m_nMarkedSinceInMarkingState = 0;
283 }
284}
285
286void
Eric Newberrya98bf932015-09-21 00:58:47 -0700287GenericLinkService::doReceivePacket(Transport::Packet&& packet)
288{
Eric Newberry86d31872015-09-23 16:24:59 -0700289 try {
Eric Newberrya1939ba2015-10-09 12:35:03 -0700290 lp::Packet pkt(packet.packet);
291
Eric Newberry185ab292017-03-28 06:45:39 +0000292 if (m_options.reliabilityOptions.isEnabled) {
293 m_reliability.processIncomingPacket(pkt);
294 }
295
Eric Newberrya1939ba2015-10-09 12:35:03 -0700296 if (!pkt.has<lp::FragmentField>()) {
297 NFD_LOG_FACE_TRACE("received IDLE packet: DROP");
298 return;
299 }
300
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700301 if ((pkt.has<lp::FragIndexField>() || pkt.has<lp::FragCountField>()) &&
302 !m_options.allowReassembly) {
303 NFD_LOG_FACE_WARN("received fragment, but reassembly disabled: DROP");
Eric Newberrya1939ba2015-10-09 12:35:03 -0700304 return;
305 }
306
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700307 bool isReassembled = false;
308 Block netPkt;
309 lp::Packet firstPkt;
310 std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.receiveFragment(packet.remoteEndpoint,
311 pkt);
312 if (isReassembled) {
313 this->decodeNetPacket(netPkt, firstPkt);
314 }
315 }
316 catch (const tlv::Error& e) {
317 ++this->nInLpInvalid;
318 NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
319 }
320}
Eric Newberry86d31872015-09-23 16:24:59 -0700321
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700322void
323GenericLinkService::decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt)
324{
325 try {
Eric Newberry86d31872015-09-23 16:24:59 -0700326 switch (netPkt.type()) {
327 case tlv::Interest:
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700328 if (firstPkt.has<lp::NackField>()) {
329 this->decodeNack(netPkt, firstPkt);
Eric Newberry86d31872015-09-23 16:24:59 -0700330 }
331 else {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700332 this->decodeInterest(netPkt, firstPkt);
Eric Newberry86d31872015-09-23 16:24:59 -0700333 }
334 break;
335 case tlv::Data:
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700336 this->decodeData(netPkt, firstPkt);
Eric Newberry86d31872015-09-23 16:24:59 -0700337 break;
338 default:
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700339 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700340 NFD_LOG_FACE_WARN("unrecognized network-layer packet TLV-TYPE " << netPkt.type() << ": DROP");
341 return;
Eric Newberrya98bf932015-09-21 00:58:47 -0700342 }
343 }
Eric Newberry86d31872015-09-23 16:24:59 -0700344 catch (const tlv::Error& e) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700345 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700346 NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
347 }
348}
349
Eric Newberry86d31872015-09-23 16:24:59 -0700350void
351GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstPkt)
352{
353 BOOST_ASSERT(netPkt.type() == tlv::Interest);
354 BOOST_ASSERT(!firstPkt.has<lp::NackField>());
355
356 // forwarding expects Interest to be created with make_shared
357 auto interest = make_shared<Interest>(netPkt);
358
Spyridon Mastorakis75c03e32016-12-06 15:20:19 -0800359 // Increment HopCount
360 if (firstPkt.has<lp::HopCountTagField>()) {
361 interest->setTag(make_shared<lp::HopCountTag>(firstPkt.get<lp::HopCountTagField>() + 1));
362 }
363
Eric Newberry86d31872015-09-23 16:24:59 -0700364 if (firstPkt.has<lp::NextHopFaceIdField>()) {
365 if (m_options.allowLocalFields) {
Junxiao Shi0de23a22015-12-03 20:07:02 +0000366 interest->setTag(make_shared<lp::NextHopFaceIdTag>(firstPkt.get<lp::NextHopFaceIdField>()));
Eric Newberry86d31872015-09-23 16:24:59 -0700367 }
368 else {
369 NFD_LOG_FACE_WARN("received NextHopFaceId, but local fields disabled: DROP");
370 return;
371 }
372 }
373
374 if (firstPkt.has<lp::CachePolicyField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700375 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700376 NFD_LOG_FACE_WARN("received CachePolicy with Interest: DROP");
377 return;
378 }
379
380 if (firstPkt.has<lp::IncomingFaceIdField>()) {
381 NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
382 }
383
Eric Newberryee400b52016-11-24 14:12:48 +0000384 if (firstPkt.has<lp::CongestionMarkField>()) {
385 interest->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
386 }
387
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700388 if (firstPkt.has<lp::NonDiscoveryField>()) {
389 if (m_options.allowSelfLearning) {
390 interest->setTag(make_shared<lp::NonDiscoveryTag>(firstPkt.get<lp::NonDiscoveryField>()));
391 }
392 else {
393 NFD_LOG_FACE_WARN("received NonDiscovery, but self-learning disabled: IGNORE");
394 }
395 }
396
397 if (firstPkt.has<lp::PrefixAnnouncementField>()) {
398 ++this->nInNetInvalid;
399 NFD_LOG_FACE_WARN("received PrefixAnnouncement with Interest: DROP");
400 return;
401 }
402
Eric Newberry86d31872015-09-23 16:24:59 -0700403 this->receiveInterest(*interest);
404}
405
406void
407GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt)
408{
409 BOOST_ASSERT(netPkt.type() == tlv::Data);
410
411 // forwarding expects Data to be created with make_shared
412 auto data = make_shared<Data>(netPkt);
413
Spyridon Mastorakis75c03e32016-12-06 15:20:19 -0800414 if (firstPkt.has<lp::HopCountTagField>()) {
415 data->setTag(make_shared<lp::HopCountTag>(firstPkt.get<lp::HopCountTagField>() + 1));
416 }
417
Eric Newberry86d31872015-09-23 16:24:59 -0700418 if (firstPkt.has<lp::NackField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700419 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700420 NFD_LOG_FACE_WARN("received Nack with Data: DROP");
421 return;
422 }
423
424 if (firstPkt.has<lp::NextHopFaceIdField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700425 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700426 NFD_LOG_FACE_WARN("received NextHopFaceId with Data: DROP");
427 return;
428 }
429
430 if (firstPkt.has<lp::CachePolicyField>()) {
Junxiao Shi6eb02712017-05-27 22:48:02 +0000431 // CachePolicy is unprivileged and does not require allowLocalFields option.
432 // In case of an invalid CachePolicyType, get<lp::CachePolicyField> will throw,
433 // so it's unnecessary to check here.
434 data->setTag(make_shared<lp::CachePolicyTag>(firstPkt.get<lp::CachePolicyField>()));
Eric Newberry86d31872015-09-23 16:24:59 -0700435 }
436
437 if (firstPkt.has<lp::IncomingFaceIdField>()) {
438 NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
439 }
440
Eric Newberryee400b52016-11-24 14:12:48 +0000441 if (firstPkt.has<lp::CongestionMarkField>()) {
442 data->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
443 }
444
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700445 if (firstPkt.has<lp::NonDiscoveryField>()) {
446 ++this->nInNetInvalid;
447 NFD_LOG_FACE_WARN("received NonDiscovery with Data: DROP");
448 return;
449 }
450
451 if (firstPkt.has<lp::PrefixAnnouncementField>()) {
452 if (m_options.allowSelfLearning) {
453 data->setTag(make_shared<lp::PrefixAnnouncementTag>(firstPkt.get<lp::PrefixAnnouncementField>()));
454 }
455 else {
456 NFD_LOG_FACE_WARN("received PrefixAnnouncement, but self-learning disabled: IGNORE");
457 }
458 }
459
Eric Newberry86d31872015-09-23 16:24:59 -0700460 this->receiveData(*data);
461}
462
463void
464GenericLinkService::decodeNack(const Block& netPkt, const lp::Packet& firstPkt)
465{
466 BOOST_ASSERT(netPkt.type() == tlv::Interest);
467 BOOST_ASSERT(firstPkt.has<lp::NackField>());
468
469 lp::Nack nack((Interest(netPkt)));
470 nack.setHeader(firstPkt.get<lp::NackField>());
471
472 if (firstPkt.has<lp::NextHopFaceIdField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700473 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700474 NFD_LOG_FACE_WARN("received NextHopFaceId with Nack: DROP");
475 return;
476 }
477
478 if (firstPkt.has<lp::CachePolicyField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700479 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700480 NFD_LOG_FACE_WARN("received CachePolicy with Nack: DROP");
481 return;
482 }
483
484 if (firstPkt.has<lp::IncomingFaceIdField>()) {
485 NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
486 }
487
Eric Newberryee400b52016-11-24 14:12:48 +0000488 if (firstPkt.has<lp::CongestionMarkField>()) {
489 nack.setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
490 }
491
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700492 if (firstPkt.has<lp::NonDiscoveryField>()) {
493 ++this->nInNetInvalid;
494 NFD_LOG_FACE_WARN("received NonDiscovery with Nack: DROP");
495 return;
496 }
497
498 if (firstPkt.has<lp::PrefixAnnouncementField>()) {
499 ++this->nInNetInvalid;
500 NFD_LOG_FACE_WARN("received PrefixAnnouncement with Nack: DROP");
501 return;
502 }
503
Eric Newberry86d31872015-09-23 16:24:59 -0700504 this->receiveNack(nack);
Eric Newberrya98bf932015-09-21 00:58:47 -0700505}
506
507} // namespace face
508} // namespace nfd