blob: a8e9710554b4a308b57709c61b7350705de23d1c [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/*
Eric Newberryb49313d2017-12-24 20:22:27 -07003 * Copyright (c) 2014-2018, 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
35NFD_LOG_INIT("GenericLinkService");
36
Eric Newberryb49313d2017-12-24 20:22:27 -070037constexpr uint32_t DEFAULT_CONGESTION_THRESHOLD_DIVISOR = 2;
38
Eric Newberry86d31872015-09-23 16:24:59 -070039GenericLinkService::Options::Options()
40 : allowLocalFields(false)
Eric Newberry4c3e6b82015-11-10 16:48:42 -070041 , allowFragmentation(false)
42 , allowReassembly(false)
Eric Newberryb49313d2017-12-24 20:22:27 -070043 , allowCongestionMarking(false)
44 , baseCongestionMarkingInterval(time::milliseconds(100)) // Interval from RFC 8289 (CoDel)
45 , defaultCongestionThreshold(65536) // This default value works well for a queue capacity of 200KiB
Teng Liangfdcbb4d2018-01-27 16:01:35 -070046 , allowSelfLearning(false)
Eric Newberry86d31872015-09-23 16:24:59 -070047{
48}
49
50GenericLinkService::GenericLinkService(const GenericLinkService::Options& options)
Eric Newberry73bcad32017-04-25 17:57:35 -070051 : m_options(options)
Eric Newberry4c3e6b82015-11-10 16:48:42 -070052 , m_fragmenter(m_options.fragmenterOptions, this)
53 , m_reassembler(m_options.reassemblerOptions, this)
Eric Newberry185ab292017-03-28 06:45:39 +000054 , m_reliability(m_options.reliabilityOptions, this)
Eric Newberry4c3e6b82015-11-10 16:48:42 -070055 , m_lastSeqNo(-2)
Eric Newberryb49313d2017-12-24 20:22:27 -070056 , m_nextMarkTime(time::steady_clock::TimePoint::max())
57 , m_lastMarkTime(time::steady_clock::TimePoint::min())
58 , m_nMarkedSinceInMarkingState(0)
Eric Newberry86d31872015-09-23 16:24:59 -070059{
Junxiao Shi0de23a22015-12-03 20:07:02 +000060 m_reassembler.beforeTimeout.connect(bind([this] { ++this->nReassemblyTimeouts; }));
Eric Newberry41aba102017-11-01 16:42:13 -070061 m_reliability.onDroppedInterest.connect([this] (const Interest& i) { this->notifyDroppedInterest(i); });
Eric Newberry73bcad32017-04-25 17:57:35 -070062 nReassembling.observe(&m_reassembler);
Eric Newberry86d31872015-09-23 16:24:59 -070063}
64
Eric Newberrya98bf932015-09-21 00:58:47 -070065void
Eric Newberry185ab292017-03-28 06:45:39 +000066GenericLinkService::setOptions(const GenericLinkService::Options& options)
67{
68 m_options = options;
69 m_fragmenter.setOptions(m_options.fragmenterOptions);
70 m_reassembler.setOptions(m_options.reassemblerOptions);
71 m_reliability.setOptions(m_options.reliabilityOptions);
72}
73
74void
75GenericLinkService::requestIdlePacket()
76{
77 // No need to request Acks to attach to this packet from LpReliability, as they are already
78 // attached in sendLpPacket
79 this->sendLpPacket({});
80}
81
82void
83GenericLinkService::sendLpPacket(lp::Packet&& pkt)
84{
85 const ssize_t mtu = this->getTransport()->getMtu();
Eric Newberryb49313d2017-12-24 20:22:27 -070086
Eric Newberry185ab292017-03-28 06:45:39 +000087 if (m_options.reliabilityOptions.isEnabled) {
88 m_reliability.piggyback(pkt, mtu);
89 }
90
Eric Newberryb49313d2017-12-24 20:22:27 -070091 if (m_options.allowCongestionMarking) {
92 checkCongestionLevel(pkt);
93 }
94
Eric Newberry185ab292017-03-28 06:45:39 +000095 Transport::Packet tp(pkt.wireEncode());
96 if (mtu != MTU_UNLIMITED && tp.packet.size() > static_cast<size_t>(mtu)) {
97 ++this->nOutOverMtu;
98 NFD_LOG_FACE_WARN("attempted to send packet over MTU limit");
99 return;
100 }
101 this->sendPacket(std::move(tp));
102}
103
104void
Eric Newberrya98bf932015-09-21 00:58:47 -0700105GenericLinkService::doSendInterest(const Interest& interest)
106{
107 lp::Packet lpPacket(interest.wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000108
Eric Newberryee400b52016-11-24 14:12:48 +0000109 encodeLpFields(interest, lpPacket);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700110
Eric Newberry41aba102017-11-01 16:42:13 -0700111 this->sendNetPacket(std::move(lpPacket), true);
Eric Newberrya98bf932015-09-21 00:58:47 -0700112}
113
114void
115GenericLinkService::doSendData(const Data& data)
116{
117 lp::Packet lpPacket(data.wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000118
Eric Newberryee400b52016-11-24 14:12:48 +0000119 encodeLpFields(data, lpPacket);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700120
Eric Newberry41aba102017-11-01 16:42:13 -0700121 this->sendNetPacket(std::move(lpPacket), false);
Eric Newberrya98bf932015-09-21 00:58:47 -0700122}
123
124void
125GenericLinkService::doSendNack(const lp::Nack& nack)
126{
127 lp::Packet lpPacket(nack.getInterest().wireEncode());
128 lpPacket.add<lp::NackField>(nack.getHeader());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000129
Eric Newberryee400b52016-11-24 14:12:48 +0000130 encodeLpFields(nack, lpPacket);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700131
Eric Newberry41aba102017-11-01 16:42:13 -0700132 this->sendNetPacket(std::move(lpPacket), false);
Eric Newberrya98bf932015-09-21 00:58:47 -0700133}
134
Junxiao Shi0de23a22015-12-03 20:07:02 +0000135void
Eric Newberry41aba102017-11-01 16:42:13 -0700136GenericLinkService::encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket)
Eric Newberry86d31872015-09-23 16:24:59 -0700137{
Eric Newberryee400b52016-11-24 14:12:48 +0000138 if (m_options.allowLocalFields) {
139 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
140 if (incomingFaceIdTag != nullptr) {
141 lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
142 }
143 }
144
145 shared_ptr<lp::CongestionMarkTag> congestionMarkTag = netPkt.getTag<lp::CongestionMarkTag>();
146 if (congestionMarkTag != nullptr) {
147 lpPacket.add<lp::CongestionMarkField>(*congestionMarkTag);
Eric Newberry86d31872015-09-23 16:24:59 -0700148 }
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700149
150 if (m_options.allowSelfLearning) {
151 shared_ptr<lp::NonDiscoveryTag> nonDiscoveryTag = netPkt.getTag<lp::NonDiscoveryTag>();
152 if (nonDiscoveryTag != nullptr) {
153 lpPacket.add<lp::NonDiscoveryField>(*nonDiscoveryTag);
154 }
155
156 shared_ptr<lp::PrefixAnnouncementTag> prefixAnnouncementTag = netPkt.getTag<lp::PrefixAnnouncementTag>();
157 if (prefixAnnouncementTag != nullptr) {
158 lpPacket.add<lp::PrefixAnnouncementField>(*prefixAnnouncementTag);
159 }
160 }
Spyridon Mastorakis0a306762016-12-06 15:20:19 -0800161
162 shared_ptr<lp::HopCountTag> hopCountTag = netPkt.getTag<lp::HopCountTag>();
163 if (hopCountTag != nullptr) {
164 lpPacket.add<lp::HopCountTagField>(*hopCountTag);
165 }
166 else {
167 lpPacket.add<lp::HopCountTagField>(0);
168 }
Eric Newberry86d31872015-09-23 16:24:59 -0700169}
170
Eric Newberrya98bf932015-09-21 00:58:47 -0700171void
Eric Newberry41aba102017-11-01 16:42:13 -0700172GenericLinkService::sendNetPacket(lp::Packet&& pkt, bool isInterest)
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700173{
174 std::vector<lp::Packet> frags;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000175 ssize_t mtu = this->getTransport()->getMtu();
176
177 // Make space for feature fields in fragments
178 if (m_options.reliabilityOptions.isEnabled && mtu != MTU_UNLIMITED) {
179 mtu -= LpReliability::RESERVED_HEADER_SPACE;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000180 }
181
Eric Newberryb49313d2017-12-24 20:22:27 -0700182 if (m_options.allowCongestionMarking && mtu != MTU_UNLIMITED) {
183 mtu -= CONGESTION_MARK_SIZE;
184 }
185
186 BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0);
187
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700188 if (m_options.allowFragmentation && mtu != MTU_UNLIMITED) {
189 bool isOk = false;
190 std::tie(isOk, frags) = m_fragmenter.fragmentPacket(pkt, mtu);
191 if (!isOk) {
192 // fragmentation failed (warning is logged by LpFragmenter)
Junxiao Shi0de23a22015-12-03 20:07:02 +0000193 ++this->nFragmentationErrors;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700194 return;
195 }
196 }
197 else {
Eric Newberry41aba102017-11-01 16:42:13 -0700198 if (m_options.reliabilityOptions.isEnabled) {
199 frags.push_back(pkt);
200 }
201 else {
202 frags.push_back(std::move(pkt));
203 }
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700204 }
205
Eric Newberry185ab292017-03-28 06:45:39 +0000206 if (frags.size() == 1) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700207 // even if indexed fragmentation is enabled, the fragmenter should not
208 // fragment the packet if it can fit in MTU
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700209 BOOST_ASSERT(!frags.front().has<lp::FragIndexField>());
210 BOOST_ASSERT(!frags.front().has<lp::FragCountField>());
211 }
212
Eric Newberry7b0071e2017-07-03 17:33:31 +0000213 // Only assign sequences to fragments if packet contains more than 1 fragment
214 if (frags.size() > 1) {
Eric Newberry185ab292017-03-28 06:45:39 +0000215 // Assign sequences to all fragments
216 this->assignSequences(frags);
217 }
218
219 if (m_options.reliabilityOptions.isEnabled && frags.front().has<lp::FragmentField>()) {
Eric Newberry41aba102017-11-01 16:42:13 -0700220 m_reliability.handleOutgoing(frags, std::move(pkt), isInterest);
Eric Newberry185ab292017-03-28 06:45:39 +0000221 }
222
223 for (lp::Packet& frag : frags) {
224 this->sendLpPacket(std::move(frag));
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700225 }
226}
227
228void
229GenericLinkService::assignSequence(lp::Packet& pkt)
230{
231 pkt.set<lp::SequenceField>(++m_lastSeqNo);
232}
233
234void
235GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts)
236{
237 std::for_each(pkts.begin(), pkts.end(), bind(&GenericLinkService::assignSequence, this, _1));
238}
239
240void
Eric Newberryb49313d2017-12-24 20:22:27 -0700241GenericLinkService::checkCongestionLevel(lp::Packet& pkt)
242{
243 ssize_t sendQueueLength = getTransport()->getSendQueueLength();
244 // This operation requires that the transport supports retrieving current send queue length
245 if (sendQueueLength < 0) {
246 return;
247 }
248
249 // To avoid overflowing the queue, set the congestion threshold to at least half of the send
250 // queue capacity.
251 size_t congestionThreshold = m_options.defaultCongestionThreshold;
252 if (getTransport()->getSendQueueCapacity() >= 0) {
253 congestionThreshold = std::min(congestionThreshold,
254 static_cast<size_t>(getTransport()->getSendQueueCapacity()) /
255 DEFAULT_CONGESTION_THRESHOLD_DIVISOR);
256 }
257
258 if (sendQueueLength > 0) {
259 NFD_LOG_FACE_TRACE("txqlen=" << sendQueueLength << " threshold=" << congestionThreshold <<
260 " capacity=" << getTransport()->getSendQueueCapacity());
261 }
262
263 if (static_cast<size_t>(sendQueueLength) > congestionThreshold) { // Send queue is congested
264 const auto now = time::steady_clock::now();
265 if (now >= m_nextMarkTime || now >= m_lastMarkTime + m_options.baseCongestionMarkingInterval) {
266 // Mark at most one initial packet per baseCongestionMarkingInterval
267 if (m_nMarkedSinceInMarkingState == 0) {
268 m_nextMarkTime = now;
269 }
270
271 // Time to mark packet
272 pkt.set<lp::CongestionMarkField>(1);
273 ++nCongestionMarked;
274 NFD_LOG_FACE_DEBUG("LpPacket was marked as congested");
275
276 ++m_nMarkedSinceInMarkingState;
277 // Decrease the marking interval by the inverse of the square root of the number of packets
278 // marked in this incident of congestion
279 m_nextMarkTime += time::nanoseconds(static_cast<time::nanoseconds::rep>(
280 m_options.baseCongestionMarkingInterval.count() /
281 std::sqrt(m_nMarkedSinceInMarkingState)));
282 m_lastMarkTime = now;
283 }
284 }
285 else if (m_nextMarkTime != time::steady_clock::TimePoint::max()) {
286 // Congestion incident has ended, so reset
287 NFD_LOG_FACE_DEBUG("Send queue length dropped below congestion threshold");
288 m_nextMarkTime = time::steady_clock::TimePoint::max();
289 m_nMarkedSinceInMarkingState = 0;
290 }
291}
292
293void
Eric Newberrya98bf932015-09-21 00:58:47 -0700294GenericLinkService::doReceivePacket(Transport::Packet&& packet)
295{
Eric Newberry86d31872015-09-23 16:24:59 -0700296 try {
Eric Newberrya1939ba2015-10-09 12:35:03 -0700297 lp::Packet pkt(packet.packet);
298
Eric Newberry185ab292017-03-28 06:45:39 +0000299 if (m_options.reliabilityOptions.isEnabled) {
300 m_reliability.processIncomingPacket(pkt);
301 }
302
Eric Newberrya1939ba2015-10-09 12:35:03 -0700303 if (!pkt.has<lp::FragmentField>()) {
304 NFD_LOG_FACE_TRACE("received IDLE packet: DROP");
305 return;
306 }
307
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700308 if ((pkt.has<lp::FragIndexField>() || pkt.has<lp::FragCountField>()) &&
309 !m_options.allowReassembly) {
310 NFD_LOG_FACE_WARN("received fragment, but reassembly disabled: DROP");
Eric Newberrya1939ba2015-10-09 12:35:03 -0700311 return;
312 }
313
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700314 bool isReassembled = false;
315 Block netPkt;
316 lp::Packet firstPkt;
317 std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.receiveFragment(packet.remoteEndpoint,
318 pkt);
319 if (isReassembled) {
320 this->decodeNetPacket(netPkt, firstPkt);
321 }
322 }
323 catch (const tlv::Error& e) {
324 ++this->nInLpInvalid;
325 NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
326 }
327}
Eric Newberry86d31872015-09-23 16:24:59 -0700328
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700329void
330GenericLinkService::decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt)
331{
332 try {
Eric Newberry86d31872015-09-23 16:24:59 -0700333 switch (netPkt.type()) {
334 case tlv::Interest:
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700335 if (firstPkt.has<lp::NackField>()) {
336 this->decodeNack(netPkt, firstPkt);
Eric Newberry86d31872015-09-23 16:24:59 -0700337 }
338 else {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700339 this->decodeInterest(netPkt, firstPkt);
Eric Newberry86d31872015-09-23 16:24:59 -0700340 }
341 break;
342 case tlv::Data:
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700343 this->decodeData(netPkt, firstPkt);
Eric Newberry86d31872015-09-23 16:24:59 -0700344 break;
345 default:
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700346 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700347 NFD_LOG_FACE_WARN("unrecognized network-layer packet TLV-TYPE " << netPkt.type() << ": DROP");
348 return;
Eric Newberrya98bf932015-09-21 00:58:47 -0700349 }
350 }
Eric Newberry86d31872015-09-23 16:24:59 -0700351 catch (const tlv::Error& e) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700352 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700353 NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
354 }
355}
356
Eric Newberry86d31872015-09-23 16:24:59 -0700357void
358GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstPkt)
359{
360 BOOST_ASSERT(netPkt.type() == tlv::Interest);
361 BOOST_ASSERT(!firstPkt.has<lp::NackField>());
362
363 // forwarding expects Interest to be created with make_shared
364 auto interest = make_shared<Interest>(netPkt);
365
Spyridon Mastorakis0a306762016-12-06 15:20:19 -0800366 // Increment HopCount
367 if (firstPkt.has<lp::HopCountTagField>()) {
368 interest->setTag(make_shared<lp::HopCountTag>(firstPkt.get<lp::HopCountTagField>() + 1));
369 }
370
Eric Newberry86d31872015-09-23 16:24:59 -0700371 if (firstPkt.has<lp::NextHopFaceIdField>()) {
372 if (m_options.allowLocalFields) {
Junxiao Shi0de23a22015-12-03 20:07:02 +0000373 interest->setTag(make_shared<lp::NextHopFaceIdTag>(firstPkt.get<lp::NextHopFaceIdField>()));
Eric Newberry86d31872015-09-23 16:24:59 -0700374 }
375 else {
376 NFD_LOG_FACE_WARN("received NextHopFaceId, but local fields disabled: DROP");
377 return;
378 }
379 }
380
381 if (firstPkt.has<lp::CachePolicyField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700382 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700383 NFD_LOG_FACE_WARN("received CachePolicy with Interest: DROP");
384 return;
385 }
386
387 if (firstPkt.has<lp::IncomingFaceIdField>()) {
388 NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
389 }
390
Eric Newberryee400b52016-11-24 14:12:48 +0000391 if (firstPkt.has<lp::CongestionMarkField>()) {
392 interest->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
393 }
394
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700395 if (firstPkt.has<lp::NonDiscoveryField>()) {
396 if (m_options.allowSelfLearning) {
397 interest->setTag(make_shared<lp::NonDiscoveryTag>(firstPkt.get<lp::NonDiscoveryField>()));
398 }
399 else {
400 NFD_LOG_FACE_WARN("received NonDiscovery, but self-learning disabled: IGNORE");
401 }
402 }
403
404 if (firstPkt.has<lp::PrefixAnnouncementField>()) {
405 ++this->nInNetInvalid;
406 NFD_LOG_FACE_WARN("received PrefixAnnouncement with Interest: DROP");
407 return;
408 }
409
Eric Newberry86d31872015-09-23 16:24:59 -0700410 this->receiveInterest(*interest);
411}
412
413void
414GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt)
415{
416 BOOST_ASSERT(netPkt.type() == tlv::Data);
417
418 // forwarding expects Data to be created with make_shared
419 auto data = make_shared<Data>(netPkt);
420
Spyridon Mastorakis0a306762016-12-06 15:20:19 -0800421 if (firstPkt.has<lp::HopCountTagField>()) {
422 data->setTag(make_shared<lp::HopCountTag>(firstPkt.get<lp::HopCountTagField>() + 1));
423 }
424
Eric Newberry86d31872015-09-23 16:24:59 -0700425 if (firstPkt.has<lp::NackField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700426 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700427 NFD_LOG_FACE_WARN("received Nack with Data: DROP");
428 return;
429 }
430
431 if (firstPkt.has<lp::NextHopFaceIdField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700432 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700433 NFD_LOG_FACE_WARN("received NextHopFaceId with Data: DROP");
434 return;
435 }
436
437 if (firstPkt.has<lp::CachePolicyField>()) {
Junxiao Shi6eb02712017-05-27 22:48:02 +0000438 // CachePolicy is unprivileged and does not require allowLocalFields option.
439 // In case of an invalid CachePolicyType, get<lp::CachePolicyField> will throw,
440 // so it's unnecessary to check here.
441 data->setTag(make_shared<lp::CachePolicyTag>(firstPkt.get<lp::CachePolicyField>()));
Eric Newberry86d31872015-09-23 16:24:59 -0700442 }
443
444 if (firstPkt.has<lp::IncomingFaceIdField>()) {
445 NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
446 }
447
Eric Newberryee400b52016-11-24 14:12:48 +0000448 if (firstPkt.has<lp::CongestionMarkField>()) {
449 data->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
450 }
451
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700452 if (firstPkt.has<lp::NonDiscoveryField>()) {
453 ++this->nInNetInvalid;
454 NFD_LOG_FACE_WARN("received NonDiscovery with Data: DROP");
455 return;
456 }
457
458 if (firstPkt.has<lp::PrefixAnnouncementField>()) {
459 if (m_options.allowSelfLearning) {
460 data->setTag(make_shared<lp::PrefixAnnouncementTag>(firstPkt.get<lp::PrefixAnnouncementField>()));
461 }
462 else {
463 NFD_LOG_FACE_WARN("received PrefixAnnouncement, but self-learning disabled: IGNORE");
464 }
465 }
466
Eric Newberry86d31872015-09-23 16:24:59 -0700467 this->receiveData(*data);
468}
469
470void
471GenericLinkService::decodeNack(const Block& netPkt, const lp::Packet& firstPkt)
472{
473 BOOST_ASSERT(netPkt.type() == tlv::Interest);
474 BOOST_ASSERT(firstPkt.has<lp::NackField>());
475
476 lp::Nack nack((Interest(netPkt)));
477 nack.setHeader(firstPkt.get<lp::NackField>());
478
479 if (firstPkt.has<lp::NextHopFaceIdField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700480 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700481 NFD_LOG_FACE_WARN("received NextHopFaceId with Nack: DROP");
482 return;
483 }
484
485 if (firstPkt.has<lp::CachePolicyField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700486 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700487 NFD_LOG_FACE_WARN("received CachePolicy with Nack: DROP");
488 return;
489 }
490
491 if (firstPkt.has<lp::IncomingFaceIdField>()) {
492 NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
493 }
494
Eric Newberryee400b52016-11-24 14:12:48 +0000495 if (firstPkt.has<lp::CongestionMarkField>()) {
496 nack.setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
497 }
498
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700499 if (firstPkt.has<lp::NonDiscoveryField>()) {
500 ++this->nInNetInvalid;
501 NFD_LOG_FACE_WARN("received NonDiscovery with Nack: DROP");
502 return;
503 }
504
505 if (firstPkt.has<lp::PrefixAnnouncementField>()) {
506 ++this->nInNetInvalid;
507 NFD_LOG_FACE_WARN("received PrefixAnnouncement with Nack: DROP");
508 return;
509 }
510
Eric Newberry86d31872015-09-23 16:24:59 -0700511 this->receiveNack(nack);
Eric Newberrya98bf932015-09-21 00:58:47 -0700512}
513
514} // namespace face
515} // namespace nfd