Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 4 | * 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 Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 27 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 28 | #include <ndn-cxx/lp/pit-token.hpp> |
Junxiao Shi | cbc8e94 | 2016-09-06 03:17:45 +0000 | [diff] [blame] | 29 | #include <ndn-cxx/lp/tags.hpp> |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 30 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 31 | #include <cmath> |
| 32 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 33 | namespace nfd { |
| 34 | namespace face { |
| 35 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 36 | NFD_LOG_INIT(GenericLinkService); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 37 | |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 38 | constexpr 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 Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 42 | GenericLinkService::GenericLinkService(const GenericLinkService::Options& options) |
Eric Newberry | 73bcad3 | 2017-04-25 17:57:35 -0700 | [diff] [blame] | 43 | : m_options(options) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 44 | , m_fragmenter(m_options.fragmenterOptions, this) |
| 45 | , m_reassembler(m_options.reassemblerOptions, this) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 46 | , m_reliability(m_options.reliabilityOptions, this) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 47 | , m_lastSeqNo(-2) |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 48 | , m_nextMarkTime(time::steady_clock::TimePoint::max()) |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 49 | , m_nMarkedSinceInMarkingState(0) |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 50 | { |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 51 | m_reassembler.beforeTimeout.connect([this] (auto...) { ++this->nReassemblyTimeouts; }); |
| 52 | m_reliability.onDroppedInterest.connect([this] (const auto& i) { this->notifyDroppedInterest(i); }); |
Eric Newberry | 73bcad3 | 2017-04-25 17:57:35 -0700 | [diff] [blame] | 53 | nReassembling.observe(&m_reassembler); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 56 | void |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 57 | GenericLinkService::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 | |
| 65 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 66 | GenericLinkService::requestIdlePacket(const EndpointId& endpointId) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 67 | { |
| 68 | // No need to request Acks to attach to this packet from LpReliability, as they are already |
| 69 | // attached in sendLpPacket |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 70 | this->sendLpPacket({}, endpointId); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 74 | GenericLinkService::sendLpPacket(lp::Packet&& pkt, const EndpointId& endpointId) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 75 | { |
| 76 | const ssize_t mtu = this->getTransport()->getMtu(); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 77 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 78 | if (m_options.reliabilityOptions.isEnabled) { |
| 79 | m_reliability.piggyback(pkt, mtu); |
| 80 | } |
| 81 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 82 | if (m_options.allowCongestionMarking) { |
| 83 | checkCongestionLevel(pkt); |
| 84 | } |
| 85 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 86 | auto block = pkt.wireEncode(); |
| 87 | if (mtu != MTU_UNLIMITED && block.size() > static_cast<size_t>(mtu)) { |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 88 | ++this->nOutOverMtu; |
| 89 | NFD_LOG_FACE_WARN("attempted to send packet over MTU limit"); |
| 90 | return; |
| 91 | } |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 92 | this->sendPacket(block, endpointId); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 96 | GenericLinkService::doSendInterest(const Interest& interest, const EndpointId& endpointId) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 97 | { |
| 98 | lp::Packet lpPacket(interest.wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 99 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 100 | encodeLpFields(interest, lpPacket); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 101 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 102 | this->sendNetPacket(std::move(lpPacket), endpointId, true); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 106 | GenericLinkService::doSendData(const Data& data, const EndpointId& endpointId) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 107 | { |
| 108 | lp::Packet lpPacket(data.wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 109 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 110 | encodeLpFields(data, lpPacket); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 111 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 112 | this->sendNetPacket(std::move(lpPacket), endpointId, false); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 116 | GenericLinkService::doSendNack(const lp::Nack& nack, const EndpointId& endpointId) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 117 | { |
| 118 | lp::Packet lpPacket(nack.getInterest().wireEncode()); |
| 119 | lpPacket.add<lp::NackField>(nack.getHeader()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 120 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 121 | encodeLpFields(nack, lpPacket); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 122 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 123 | this->sendNetPacket(std::move(lpPacket), endpointId, false); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 126 | void |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 127 | GenericLinkService::encodeLpFields(const ndn::PacketBase& netPkt, lp::Packet& lpPacket) |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 128 | { |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 129 | if (m_options.allowLocalFields) { |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 130 | auto incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 131 | if (incomingFaceIdTag != nullptr) { |
| 132 | lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag); |
| 133 | } |
| 134 | } |
| 135 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 136 | auto congestionMarkTag = netPkt.getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 137 | if (congestionMarkTag != nullptr) { |
| 138 | lpPacket.add<lp::CongestionMarkField>(*congestionMarkTag); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 139 | } |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 140 | |
| 141 | if (m_options.allowSelfLearning) { |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 142 | auto nonDiscoveryTag = netPkt.getTag<lp::NonDiscoveryTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 143 | if (nonDiscoveryTag != nullptr) { |
| 144 | lpPacket.add<lp::NonDiscoveryField>(*nonDiscoveryTag); |
| 145 | } |
| 146 | |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 147 | auto prefixAnnouncementTag = netPkt.getTag<lp::PrefixAnnouncementTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 148 | if (prefixAnnouncementTag != nullptr) { |
| 149 | lpPacket.add<lp::PrefixAnnouncementField>(*prefixAnnouncementTag); |
| 150 | } |
| 151 | } |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 152 | |
| 153 | auto pitToken = netPkt.getTag<lp::PitToken>(); |
| 154 | if (pitToken != nullptr) { |
| 155 | lpPacket.add<lp::PitTokenField>(*pitToken); |
| 156 | } |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 159 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 160 | GenericLinkService::sendNetPacket(lp::Packet&& pkt, const EndpointId& endpointId, bool isInterest) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 161 | { |
| 162 | std::vector<lp::Packet> frags; |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 163 | 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 Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 170 | if (m_options.allowCongestionMarking && mtu != MTU_UNLIMITED) { |
| 171 | mtu -= CONGESTION_MARK_SIZE; |
| 172 | } |
| 173 | |
| 174 | BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0); |
| 175 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 176 | 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 Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 181 | ++this->nFragmentationErrors; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 182 | return; |
| 183 | } |
| 184 | } |
| 185 | else { |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 186 | if (m_options.reliabilityOptions.isEnabled) { |
| 187 | frags.push_back(pkt); |
| 188 | } |
| 189 | else { |
| 190 | frags.push_back(std::move(pkt)); |
| 191 | } |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 194 | if (frags.size() == 1) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 195 | // even if indexed fragmentation is enabled, the fragmenter should not |
| 196 | // fragment the packet if it can fit in MTU |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 197 | BOOST_ASSERT(!frags.front().has<lp::FragIndexField>()); |
| 198 | BOOST_ASSERT(!frags.front().has<lp::FragCountField>()); |
| 199 | } |
| 200 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 201 | // Only assign sequences to fragments if packet contains more than 1 fragment |
| 202 | if (frags.size() > 1) { |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 203 | // Assign sequences to all fragments |
| 204 | this->assignSequences(frags); |
| 205 | } |
| 206 | |
| 207 | if (m_options.reliabilityOptions.isEnabled && frags.front().has<lp::FragmentField>()) { |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 208 | m_reliability.handleOutgoing(frags, std::move(pkt), isInterest); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | for (lp::Packet& frag : frags) { |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 212 | this->sendLpPacket(std::move(frag), endpointId); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
| 216 | void |
| 217 | GenericLinkService::assignSequence(lp::Packet& pkt) |
| 218 | { |
| 219 | pkt.set<lp::SequenceField>(++m_lastSeqNo); |
| 220 | } |
| 221 | |
| 222 | void |
| 223 | GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts) |
| 224 | { |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 225 | std::for_each(pkts.begin(), pkts.end(), [this] (auto& pkt) { this->assignSequence(pkt); }); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | void |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 229 | GenericLinkService::checkCongestionLevel(lp::Packet& pkt) |
| 230 | { |
| 231 | ssize_t sendQueueLength = getTransport()->getSendQueueLength(); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 232 | // The transport must support retrieving the current send queue length |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 233 | if (sendQueueLength < 0) { |
| 234 | return; |
| 235 | } |
| 236 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 237 | if (sendQueueLength > 0) { |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 238 | NFD_LOG_FACE_TRACE("txqlen=" << sendQueueLength << " threshold=" << |
| 239 | m_options.defaultCongestionThreshold << " capacity=" << |
| 240 | getTransport()->getSendQueueCapacity()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 243 | // sendQueue is above target |
| 244 | if (static_cast<size_t>(sendQueueLength) > m_options.defaultCongestionThreshold) { |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 245 | const auto now = time::steady_clock::now(); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 246 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 247 | 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 Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 252 | 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 Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 259 | time::nanoseconds interval(static_cast<time::nanoseconds::rep>( |
| 260 | m_options.baseCongestionMarkingInterval.count() / |
| 261 | std::sqrt(m_nMarkedSinceInMarkingState + 1))); |
| 262 | m_nextMarkTime += interval; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 263 | } |
| 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 | |
| 273 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 274 | GenericLinkService::doReceivePacket(const Block& packet, const EndpointId& endpoint) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 275 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 276 | try { |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 277 | lp::Packet pkt(packet); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 278 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 279 | if (m_options.reliabilityOptions.isEnabled) { |
| 280 | m_reliability.processIncomingPacket(pkt); |
| 281 | } |
| 282 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 283 | if (!pkt.has<lp::FragmentField>()) { |
| 284 | NFD_LOG_FACE_TRACE("received IDLE packet: DROP"); |
| 285 | return; |
| 286 | } |
| 287 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 288 | 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 Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 294 | bool isReassembled = false; |
| 295 | Block netPkt; |
| 296 | lp::Packet firstPkt; |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 297 | std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.receiveFragment(endpoint, pkt); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 298 | if (isReassembled) { |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 299 | this->decodeNetPacket(netPkt, firstPkt, endpoint); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | catch (const tlv::Error& e) { |
| 303 | ++this->nInLpInvalid; |
| 304 | NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP"); |
| 305 | } |
| 306 | } |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 307 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 308 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 309 | GenericLinkService::decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt, |
| 310 | const EndpointId& endpointId) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 311 | { |
| 312 | try { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 313 | switch (netPkt.type()) { |
| 314 | case tlv::Interest: |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 315 | if (firstPkt.has<lp::NackField>()) { |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 316 | this->decodeNack(netPkt, firstPkt, endpointId); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 317 | } |
| 318 | else { |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 319 | this->decodeInterest(netPkt, firstPkt, endpointId); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 320 | } |
| 321 | break; |
| 322 | case tlv::Data: |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 323 | this->decodeData(netPkt, firstPkt, endpointId); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 324 | break; |
| 325 | default: |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 326 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 327 | NFD_LOG_FACE_WARN("unrecognized network-layer packet TLV-TYPE " << netPkt.type() << ": DROP"); |
| 328 | return; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 331 | catch (const tlv::Error& e) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 332 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 333 | NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP"); |
| 334 | } |
| 335 | } |
| 336 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 337 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 338 | GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstPkt, |
| 339 | const EndpointId& endpointId) |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 340 | { |
| 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 Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 349 | interest->setTag(make_shared<lp::NextHopFaceIdTag>(firstPkt.get<lp::NextHopFaceIdField>())); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 350 | } |
| 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 Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 358 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 359 | 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 Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 367 | if (firstPkt.has<lp::CongestionMarkField>()) { |
| 368 | interest->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>())); |
| 369 | } |
| 370 | |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 371 | 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 Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 386 | if (firstPkt.has<lp::PitTokenField>()) { |
| 387 | interest->setTag(make_shared<lp::PitToken>(firstPkt.get<lp::PitTokenField>())); |
| 388 | } |
| 389 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 390 | this->receiveInterest(*interest, endpointId); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 394 | GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt, |
| 395 | const EndpointId& endpointId) |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 396 | { |
| 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 Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 403 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 404 | NFD_LOG_FACE_WARN("received Nack with Data: DROP"); |
| 405 | return; |
| 406 | } |
| 407 | |
| 408 | if (firstPkt.has<lp::NextHopFaceIdField>()) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 409 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 410 | NFD_LOG_FACE_WARN("received NextHopFaceId with Data: DROP"); |
| 411 | return; |
| 412 | } |
| 413 | |
| 414 | if (firstPkt.has<lp::CachePolicyField>()) { |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 415 | // 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 Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | if (firstPkt.has<lp::IncomingFaceIdField>()) { |
| 422 | NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE"); |
| 423 | } |
| 424 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 425 | if (firstPkt.has<lp::CongestionMarkField>()) { |
| 426 | data->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>())); |
| 427 | } |
| 428 | |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 429 | 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 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 444 | this->receiveData(*data, endpointId); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 448 | GenericLinkService::decodeNack(const Block& netPkt, const lp::Packet& firstPkt, |
| 449 | const EndpointId& endpointId) |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 450 | { |
| 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 Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 458 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 459 | NFD_LOG_FACE_WARN("received NextHopFaceId with Nack: DROP"); |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | if (firstPkt.has<lp::CachePolicyField>()) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 464 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 465 | 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 Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 473 | if (firstPkt.has<lp::CongestionMarkField>()) { |
| 474 | nack.setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>())); |
| 475 | } |
| 476 | |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 477 | 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 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 489 | this->receiveNack(nack, endpointId); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | } // namespace face |
| 493 | } // namespace nfd |