blob: 601c041847811402f676a5278dcdbeb985637a2f [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 Shi606d5dd2019-09-23 12:47:44 -060028#include <ndn-cxx/lp/pit-token.hpp>
Junxiao Shicbc8e942016-09-06 03:17:45 +000029#include <ndn-cxx/lp/tags.hpp>
Eric Newberrya98bf932015-09-21 00:58:47 -070030
Eric Newberryb49313d2017-12-24 20:22:27 -070031#include <cmath>
32
Eric Newberrya98bf932015-09-21 00:58:47 -070033namespace nfd {
34namespace face {
35
Davide Pesaventoa3148082018-04-12 18:21:54 -040036NFD_LOG_INIT(GenericLinkService);
Eric Newberrya98bf932015-09-21 00:58:47 -070037
Davide Pesaventoa8098582019-03-31 15:48:02 -040038constexpr size_t CONGESTION_MARK_SIZE = tlv::sizeOfVarNumber(lp::tlv::CongestionMark) + // type
39 tlv::sizeOfVarNumber(sizeof(uint64_t)) + // length
40 tlv::sizeOfNonNegativeInteger(UINT64_MAX); // value
41
Eric Newberry86d31872015-09-23 16:24:59 -070042GenericLinkService::GenericLinkService(const GenericLinkService::Options& options)
Eric Newberry73bcad32017-04-25 17:57:35 -070043 : m_options(options)
Eric Newberry4c3e6b82015-11-10 16:48:42 -070044 , m_fragmenter(m_options.fragmenterOptions, this)
45 , m_reassembler(m_options.reassemblerOptions, this)
Eric Newberry185ab292017-03-28 06:45:39 +000046 , m_reliability(m_options.reliabilityOptions, this)
Eric Newberry4c3e6b82015-11-10 16:48:42 -070047 , m_lastSeqNo(-2)
Eric Newberryb49313d2017-12-24 20:22:27 -070048 , m_nextMarkTime(time::steady_clock::TimePoint::max())
Eric Newberryb49313d2017-12-24 20:22:27 -070049 , m_nMarkedSinceInMarkingState(0)
Eric Newberry86d31872015-09-23 16:24:59 -070050{
Davide Pesaventoe4b22382018-06-10 14:37:24 -040051 m_reassembler.beforeTimeout.connect([this] (auto...) { ++this->nReassemblyTimeouts; });
52 m_reliability.onDroppedInterest.connect([this] (const auto& i) { this->notifyDroppedInterest(i); });
Eric Newberry73bcad32017-04-25 17:57:35 -070053 nReassembling.observe(&m_reassembler);
Eric Newberry86d31872015-09-23 16:24:59 -070054}
55
Eric Newberrya98bf932015-09-21 00:58:47 -070056void
Eric Newberry185ab292017-03-28 06:45:39 +000057GenericLinkService::setOptions(const GenericLinkService::Options& options)
58{
59 m_options = options;
60 m_fragmenter.setOptions(m_options.fragmenterOptions);
61 m_reassembler.setOptions(m_options.reassemblerOptions);
62 m_reliability.setOptions(m_options.reliabilityOptions);
63}
64
65void
ashiqopu075bb7d2019-03-10 01:38:21 +000066GenericLinkService::requestIdlePacket(const EndpointId& endpointId)
Eric Newberry185ab292017-03-28 06:45:39 +000067{
68 // No need to request Acks to attach to this packet from LpReliability, as they are already
69 // attached in sendLpPacket
ashiqopu075bb7d2019-03-10 01:38:21 +000070 this->sendLpPacket({}, endpointId);
Eric Newberry185ab292017-03-28 06:45:39 +000071}
72
73void
ashiqopu075bb7d2019-03-10 01:38:21 +000074GenericLinkService::sendLpPacket(lp::Packet&& pkt, const EndpointId& endpointId)
Eric Newberry185ab292017-03-28 06:45:39 +000075{
76 const ssize_t mtu = this->getTransport()->getMtu();
Eric Newberryb49313d2017-12-24 20:22:27 -070077
Eric Newberry185ab292017-03-28 06:45:39 +000078 if (m_options.reliabilityOptions.isEnabled) {
79 m_reliability.piggyback(pkt, mtu);
80 }
81
Eric Newberryb49313d2017-12-24 20:22:27 -070082 if (m_options.allowCongestionMarking) {
83 checkCongestionLevel(pkt);
84 }
85
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040086 auto block = pkt.wireEncode();
87 if (mtu != MTU_UNLIMITED && block.size() > static_cast<size_t>(mtu)) {
Eric Newberry185ab292017-03-28 06:45:39 +000088 ++this->nOutOverMtu;
89 NFD_LOG_FACE_WARN("attempted to send packet over MTU limit");
90 return;
91 }
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040092 this->sendPacket(block, endpointId);
Eric Newberry185ab292017-03-28 06:45:39 +000093}
94
95void
ashiqopu075bb7d2019-03-10 01:38:21 +000096GenericLinkService::doSendInterest(const Interest& interest, const EndpointId& endpointId)
Eric Newberrya98bf932015-09-21 00:58:47 -070097{
98 lp::Packet lpPacket(interest.wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +000099
Eric Newberryee400b52016-11-24 14:12:48 +0000100 encodeLpFields(interest, lpPacket);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700101
ashiqopu075bb7d2019-03-10 01:38:21 +0000102 this->sendNetPacket(std::move(lpPacket), endpointId, true);
Eric Newberrya98bf932015-09-21 00:58:47 -0700103}
104
105void
ashiqopu075bb7d2019-03-10 01:38:21 +0000106GenericLinkService::doSendData(const Data& data, const EndpointId& endpointId)
Eric Newberrya98bf932015-09-21 00:58:47 -0700107{
108 lp::Packet lpPacket(data.wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000109
Eric Newberryee400b52016-11-24 14:12:48 +0000110 encodeLpFields(data, lpPacket);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700111
ashiqopu075bb7d2019-03-10 01:38:21 +0000112 this->sendNetPacket(std::move(lpPacket), endpointId, false);
Eric Newberrya98bf932015-09-21 00:58:47 -0700113}
114
115void
ashiqopu075bb7d2019-03-10 01:38:21 +0000116GenericLinkService::doSendNack(const lp::Nack& nack, const EndpointId& endpointId)
Eric Newberrya98bf932015-09-21 00:58:47 -0700117{
118 lp::Packet lpPacket(nack.getInterest().wireEncode());
119 lpPacket.add<lp::NackField>(nack.getHeader());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000120
Eric Newberryee400b52016-11-24 14:12:48 +0000121 encodeLpFields(nack, lpPacket);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700122
ashiqopu075bb7d2019-03-10 01:38:21 +0000123 this->sendNetPacket(std::move(lpPacket), endpointId, false);
Eric Newberrya98bf932015-09-21 00:58:47 -0700124}
125
Junxiao Shi0de23a22015-12-03 20:07:02 +0000126void
Eric Newberry41aba102017-11-01 16:42:13 -0700127GenericLinkService::encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket)
Eric Newberry86d31872015-09-23 16:24:59 -0700128{
Eric Newberryee400b52016-11-24 14:12:48 +0000129 if (m_options.allowLocalFields) {
Junxiao Shi606d5dd2019-09-23 12:47:44 -0600130 auto incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
Eric Newberryee400b52016-11-24 14:12:48 +0000131 if (incomingFaceIdTag != nullptr) {
132 lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
133 }
134 }
135
Junxiao Shi606d5dd2019-09-23 12:47:44 -0600136 auto congestionMarkTag = netPkt.getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +0000137 if (congestionMarkTag != nullptr) {
138 lpPacket.add<lp::CongestionMarkField>(*congestionMarkTag);
Eric Newberry86d31872015-09-23 16:24:59 -0700139 }
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700140
141 if (m_options.allowSelfLearning) {
Junxiao Shi606d5dd2019-09-23 12:47:44 -0600142 auto nonDiscoveryTag = netPkt.getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700143 if (nonDiscoveryTag != nullptr) {
144 lpPacket.add<lp::NonDiscoveryField>(*nonDiscoveryTag);
145 }
146
Junxiao Shi606d5dd2019-09-23 12:47:44 -0600147 auto prefixAnnouncementTag = netPkt.getTag<lp::PrefixAnnouncementTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700148 if (prefixAnnouncementTag != nullptr) {
149 lpPacket.add<lp::PrefixAnnouncementField>(*prefixAnnouncementTag);
150 }
151 }
Junxiao Shi606d5dd2019-09-23 12:47:44 -0600152
153 auto pitToken = netPkt.getTag<lp::PitToken>();
154 if (pitToken != nullptr) {
155 lpPacket.add<lp::PitTokenField>(*pitToken);
156 }
Eric Newberry86d31872015-09-23 16:24:59 -0700157}
158
Eric Newberrya98bf932015-09-21 00:58:47 -0700159void
ashiqopu075bb7d2019-03-10 01:38:21 +0000160GenericLinkService::sendNetPacket(lp::Packet&& pkt, const EndpointId& endpointId, bool isInterest)
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700161{
162 std::vector<lp::Packet> frags;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000163 ssize_t mtu = this->getTransport()->getMtu();
164
165 // Make space for feature fields in fragments
166 if (m_options.reliabilityOptions.isEnabled && mtu != MTU_UNLIMITED) {
167 mtu -= LpReliability::RESERVED_HEADER_SPACE;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000168 }
169
Eric Newberryb49313d2017-12-24 20:22:27 -0700170 if (m_options.allowCongestionMarking && mtu != MTU_UNLIMITED) {
171 mtu -= CONGESTION_MARK_SIZE;
172 }
173
174 BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0);
175
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700176 if (m_options.allowFragmentation && mtu != MTU_UNLIMITED) {
177 bool isOk = false;
178 std::tie(isOk, frags) = m_fragmenter.fragmentPacket(pkt, mtu);
179 if (!isOk) {
180 // fragmentation failed (warning is logged by LpFragmenter)
Junxiao Shi0de23a22015-12-03 20:07:02 +0000181 ++this->nFragmentationErrors;
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700182 return;
183 }
184 }
185 else {
Eric Newberry41aba102017-11-01 16:42:13 -0700186 if (m_options.reliabilityOptions.isEnabled) {
187 frags.push_back(pkt);
188 }
189 else {
190 frags.push_back(std::move(pkt));
191 }
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700192 }
193
Eric Newberry185ab292017-03-28 06:45:39 +0000194 if (frags.size() == 1) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700195 // even if indexed fragmentation is enabled, the fragmenter should not
196 // fragment the packet if it can fit in MTU
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700197 BOOST_ASSERT(!frags.front().has<lp::FragIndexField>());
198 BOOST_ASSERT(!frags.front().has<lp::FragCountField>());
199 }
200
Eric Newberry7b0071e2017-07-03 17:33:31 +0000201 // Only assign sequences to fragments if packet contains more than 1 fragment
202 if (frags.size() > 1) {
Eric Newberry185ab292017-03-28 06:45:39 +0000203 // Assign sequences to all fragments
204 this->assignSequences(frags);
205 }
206
207 if (m_options.reliabilityOptions.isEnabled && frags.front().has<lp::FragmentField>()) {
Eric Newberry41aba102017-11-01 16:42:13 -0700208 m_reliability.handleOutgoing(frags, std::move(pkt), isInterest);
Eric Newberry185ab292017-03-28 06:45:39 +0000209 }
210
211 for (lp::Packet& frag : frags) {
ashiqopu075bb7d2019-03-10 01:38:21 +0000212 this->sendLpPacket(std::move(frag), endpointId);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700213 }
214}
215
216void
217GenericLinkService::assignSequence(lp::Packet& pkt)
218{
219 pkt.set<lp::SequenceField>(++m_lastSeqNo);
220}
221
222void
223GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts)
224{
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400225 std::for_each(pkts.begin(), pkts.end(), [this] (auto& pkt) { this->assignSequence(pkt); });
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700226}
227
228void
Eric Newberryb49313d2017-12-24 20:22:27 -0700229GenericLinkService::checkCongestionLevel(lp::Packet& pkt)
230{
231 ssize_t sendQueueLength = getTransport()->getSendQueueLength();
Klaus Schneider380668b2019-10-02 01:21:13 -0700232 // The transport must support retrieving the current send queue length
Eric Newberryb49313d2017-12-24 20:22:27 -0700233 if (sendQueueLength < 0) {
234 return;
235 }
236
Eric Newberryb49313d2017-12-24 20:22:27 -0700237 if (sendQueueLength > 0) {
Klaus Schneider380668b2019-10-02 01:21:13 -0700238 NFD_LOG_FACE_TRACE("txqlen=" << sendQueueLength << " threshold=" <<
239 m_options.defaultCongestionThreshold << " capacity=" <<
240 getTransport()->getSendQueueCapacity());
Eric Newberryb49313d2017-12-24 20:22:27 -0700241 }
242
Klaus Schneider380668b2019-10-02 01:21:13 -0700243 // sendQueue is above target
244 if (static_cast<size_t>(sendQueueLength) > m_options.defaultCongestionThreshold) {
Eric Newberryb49313d2017-12-24 20:22:27 -0700245 const auto now = time::steady_clock::now();
Eric Newberryb49313d2017-12-24 20:22:27 -0700246
Klaus Schneider380668b2019-10-02 01:21:13 -0700247 if (m_nextMarkTime == time::steady_clock::TimePoint::max()) {
248 m_nextMarkTime = now + m_options.baseCongestionMarkingInterval;
249 }
250 // Mark packet if sendQueue stays above target for one interval
251 else if (now >= m_nextMarkTime) {
Eric Newberryb49313d2017-12-24 20:22:27 -0700252 pkt.set<lp::CongestionMarkField>(1);
253 ++nCongestionMarked;
254 NFD_LOG_FACE_DEBUG("LpPacket was marked as congested");
255
256 ++m_nMarkedSinceInMarkingState;
257 // Decrease the marking interval by the inverse of the square root of the number of packets
258 // marked in this incident of congestion
Klaus Schneider380668b2019-10-02 01:21:13 -0700259 time::nanoseconds interval(static_cast<time::nanoseconds::rep>(
260 m_options.baseCongestionMarkingInterval.count() /
261 std::sqrt(m_nMarkedSinceInMarkingState + 1)));
262 m_nextMarkTime += interval;
Eric Newberryb49313d2017-12-24 20:22:27 -0700263 }
264 }
265 else if (m_nextMarkTime != time::steady_clock::TimePoint::max()) {
266 // Congestion incident has ended, so reset
267 NFD_LOG_FACE_DEBUG("Send queue length dropped below congestion threshold");
268 m_nextMarkTime = time::steady_clock::TimePoint::max();
269 m_nMarkedSinceInMarkingState = 0;
270 }
271}
272
273void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400274GenericLinkService::doReceivePacket(const Block& packet, const EndpointId& endpoint)
Eric Newberrya98bf932015-09-21 00:58:47 -0700275{
Eric Newberry86d31872015-09-23 16:24:59 -0700276 try {
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400277 lp::Packet pkt(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -0700278
Eric Newberry185ab292017-03-28 06:45:39 +0000279 if (m_options.reliabilityOptions.isEnabled) {
280 m_reliability.processIncomingPacket(pkt);
281 }
282
Eric Newberrya1939ba2015-10-09 12:35:03 -0700283 if (!pkt.has<lp::FragmentField>()) {
284 NFD_LOG_FACE_TRACE("received IDLE packet: DROP");
285 return;
286 }
287
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700288 if ((pkt.has<lp::FragIndexField>() || pkt.has<lp::FragCountField>()) &&
289 !m_options.allowReassembly) {
290 NFD_LOG_FACE_WARN("received fragment, but reassembly disabled: DROP");
Eric Newberrya1939ba2015-10-09 12:35:03 -0700291 return;
292 }
293
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700294 bool isReassembled = false;
295 Block netPkt;
296 lp::Packet firstPkt;
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400297 std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.receiveFragment(endpoint, pkt);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700298 if (isReassembled) {
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400299 this->decodeNetPacket(netPkt, firstPkt, endpoint);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700300 }
301 }
302 catch (const tlv::Error& e) {
303 ++this->nInLpInvalid;
304 NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
305 }
306}
Eric Newberry86d31872015-09-23 16:24:59 -0700307
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700308void
ashiqopu075bb7d2019-03-10 01:38:21 +0000309GenericLinkService::decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt,
310 const EndpointId& endpointId)
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700311{
312 try {
Eric Newberry86d31872015-09-23 16:24:59 -0700313 switch (netPkt.type()) {
314 case tlv::Interest:
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700315 if (firstPkt.has<lp::NackField>()) {
ashiqopu075bb7d2019-03-10 01:38:21 +0000316 this->decodeNack(netPkt, firstPkt, endpointId);
Eric Newberry86d31872015-09-23 16:24:59 -0700317 }
318 else {
ashiqopu075bb7d2019-03-10 01:38:21 +0000319 this->decodeInterest(netPkt, firstPkt, endpointId);
Eric Newberry86d31872015-09-23 16:24:59 -0700320 }
321 break;
322 case tlv::Data:
ashiqopu075bb7d2019-03-10 01:38:21 +0000323 this->decodeData(netPkt, firstPkt, endpointId);
Eric Newberry86d31872015-09-23 16:24:59 -0700324 break;
325 default:
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700326 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700327 NFD_LOG_FACE_WARN("unrecognized network-layer packet TLV-TYPE " << netPkt.type() << ": DROP");
328 return;
Eric Newberrya98bf932015-09-21 00:58:47 -0700329 }
330 }
Eric Newberry86d31872015-09-23 16:24:59 -0700331 catch (const tlv::Error& e) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700332 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700333 NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
334 }
335}
336
Eric Newberry86d31872015-09-23 16:24:59 -0700337void
ashiqopu075bb7d2019-03-10 01:38:21 +0000338GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstPkt,
339 const EndpointId& endpointId)
Eric Newberry86d31872015-09-23 16:24:59 -0700340{
341 BOOST_ASSERT(netPkt.type() == tlv::Interest);
342 BOOST_ASSERT(!firstPkt.has<lp::NackField>());
343
344 // forwarding expects Interest to be created with make_shared
345 auto interest = make_shared<Interest>(netPkt);
346
347 if (firstPkt.has<lp::NextHopFaceIdField>()) {
348 if (m_options.allowLocalFields) {
Junxiao Shi0de23a22015-12-03 20:07:02 +0000349 interest->setTag(make_shared<lp::NextHopFaceIdTag>(firstPkt.get<lp::NextHopFaceIdField>()));
Eric Newberry86d31872015-09-23 16:24:59 -0700350 }
351 else {
352 NFD_LOG_FACE_WARN("received NextHopFaceId, but local fields disabled: DROP");
353 return;
354 }
355 }
356
357 if (firstPkt.has<lp::CachePolicyField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700358 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700359 NFD_LOG_FACE_WARN("received CachePolicy with Interest: DROP");
360 return;
361 }
362
363 if (firstPkt.has<lp::IncomingFaceIdField>()) {
364 NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
365 }
366
Eric Newberryee400b52016-11-24 14:12:48 +0000367 if (firstPkt.has<lp::CongestionMarkField>()) {
368 interest->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
369 }
370
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700371 if (firstPkt.has<lp::NonDiscoveryField>()) {
372 if (m_options.allowSelfLearning) {
373 interest->setTag(make_shared<lp::NonDiscoveryTag>(firstPkt.get<lp::NonDiscoveryField>()));
374 }
375 else {
376 NFD_LOG_FACE_WARN("received NonDiscovery, but self-learning disabled: IGNORE");
377 }
378 }
379
380 if (firstPkt.has<lp::PrefixAnnouncementField>()) {
381 ++this->nInNetInvalid;
382 NFD_LOG_FACE_WARN("received PrefixAnnouncement with Interest: DROP");
383 return;
384 }
385
Junxiao Shi606d5dd2019-09-23 12:47:44 -0600386 if (firstPkt.has<lp::PitTokenField>()) {
387 interest->setTag(make_shared<lp::PitToken>(firstPkt.get<lp::PitTokenField>()));
388 }
389
ashiqopu075bb7d2019-03-10 01:38:21 +0000390 this->receiveInterest(*interest, endpointId);
Eric Newberry86d31872015-09-23 16:24:59 -0700391}
392
393void
ashiqopu075bb7d2019-03-10 01:38:21 +0000394GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt,
395 const EndpointId& endpointId)
Eric Newberry86d31872015-09-23 16:24:59 -0700396{
397 BOOST_ASSERT(netPkt.type() == tlv::Data);
398
399 // forwarding expects Data to be created with make_shared
400 auto data = make_shared<Data>(netPkt);
401
402 if (firstPkt.has<lp::NackField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700403 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700404 NFD_LOG_FACE_WARN("received Nack with Data: DROP");
405 return;
406 }
407
408 if (firstPkt.has<lp::NextHopFaceIdField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700409 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700410 NFD_LOG_FACE_WARN("received NextHopFaceId with Data: DROP");
411 return;
412 }
413
414 if (firstPkt.has<lp::CachePolicyField>()) {
Junxiao Shi6eb02712017-05-27 22:48:02 +0000415 // CachePolicy is unprivileged and does not require allowLocalFields option.
416 // In case of an invalid CachePolicyType, get<lp::CachePolicyField> will throw,
417 // so it's unnecessary to check here.
418 data->setTag(make_shared<lp::CachePolicyTag>(firstPkt.get<lp::CachePolicyField>()));
Eric Newberry86d31872015-09-23 16:24:59 -0700419 }
420
421 if (firstPkt.has<lp::IncomingFaceIdField>()) {
422 NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
423 }
424
Eric Newberryee400b52016-11-24 14:12:48 +0000425 if (firstPkt.has<lp::CongestionMarkField>()) {
426 data->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
427 }
428
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700429 if (firstPkt.has<lp::NonDiscoveryField>()) {
430 ++this->nInNetInvalid;
431 NFD_LOG_FACE_WARN("received NonDiscovery with Data: DROP");
432 return;
433 }
434
435 if (firstPkt.has<lp::PrefixAnnouncementField>()) {
436 if (m_options.allowSelfLearning) {
437 data->setTag(make_shared<lp::PrefixAnnouncementTag>(firstPkt.get<lp::PrefixAnnouncementField>()));
438 }
439 else {
440 NFD_LOG_FACE_WARN("received PrefixAnnouncement, but self-learning disabled: IGNORE");
441 }
442 }
443
ashiqopu075bb7d2019-03-10 01:38:21 +0000444 this->receiveData(*data, endpointId);
Eric Newberry86d31872015-09-23 16:24:59 -0700445}
446
447void
ashiqopu075bb7d2019-03-10 01:38:21 +0000448GenericLinkService::decodeNack(const Block& netPkt, const lp::Packet& firstPkt,
449 const EndpointId& endpointId)
Eric Newberry86d31872015-09-23 16:24:59 -0700450{
451 BOOST_ASSERT(netPkt.type() == tlv::Interest);
452 BOOST_ASSERT(firstPkt.has<lp::NackField>());
453
454 lp::Nack nack((Interest(netPkt)));
455 nack.setHeader(firstPkt.get<lp::NackField>());
456
457 if (firstPkt.has<lp::NextHopFaceIdField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700458 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700459 NFD_LOG_FACE_WARN("received NextHopFaceId with Nack: DROP");
460 return;
461 }
462
463 if (firstPkt.has<lp::CachePolicyField>()) {
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700464 ++this->nInNetInvalid;
Eric Newberry86d31872015-09-23 16:24:59 -0700465 NFD_LOG_FACE_WARN("received CachePolicy with Nack: DROP");
466 return;
467 }
468
469 if (firstPkt.has<lp::IncomingFaceIdField>()) {
470 NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
471 }
472
Eric Newberryee400b52016-11-24 14:12:48 +0000473 if (firstPkt.has<lp::CongestionMarkField>()) {
474 nack.setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
475 }
476
Teng Liangfdcbb4d2018-01-27 16:01:35 -0700477 if (firstPkt.has<lp::NonDiscoveryField>()) {
478 ++this->nInNetInvalid;
479 NFD_LOG_FACE_WARN("received NonDiscovery with Nack: DROP");
480 return;
481 }
482
483 if (firstPkt.has<lp::PrefixAnnouncementField>()) {
484 ++this->nInNetInvalid;
485 NFD_LOG_FACE_WARN("received PrefixAnnouncement with Nack: DROP");
486 return;
487 }
488
ashiqopu075bb7d2019-03-10 01:38:21 +0000489 this->receiveNack(nack, endpointId);
Eric Newberrya98bf932015-09-21 00:58:47 -0700490}
491
492} // namespace face
493} // namespace nfd