Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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" |
Junxiao Shi | cbc8e94 | 2016-09-06 03:17:45 +0000 | [diff] [blame] | 27 | #include <ndn-cxx/lp/tags.hpp> |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 28 | |
| 29 | namespace nfd { |
| 30 | namespace face { |
| 31 | |
| 32 | NFD_LOG_INIT("GenericLinkService"); |
| 33 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 34 | GenericLinkServiceCounters::GenericLinkServiceCounters(const LpReassembler& reassembler) |
| 35 | : nReassembling(reassembler) |
| 36 | { |
| 37 | } |
| 38 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 39 | GenericLinkService::Options::Options() |
| 40 | : allowLocalFields(false) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 41 | , allowFragmentation(false) |
| 42 | , allowReassembly(false) |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
| 46 | GenericLinkService::GenericLinkService(const GenericLinkService::Options& options) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 47 | : GenericLinkServiceCounters(m_reassembler) |
| 48 | , m_options(options) |
| 49 | , m_fragmenter(m_options.fragmenterOptions, this) |
| 50 | , m_reassembler(m_options.reassemblerOptions, this) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 51 | , m_reliability(m_options.reliabilityOptions, this) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 52 | , m_lastSeqNo(-2) |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 53 | { |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 54 | m_reassembler.beforeTimeout.connect(bind([this] { ++this->nReassemblyTimeouts; })); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 57 | void |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 58 | GenericLinkService::setOptions(const GenericLinkService::Options& options) |
| 59 | { |
| 60 | m_options = options; |
| 61 | m_fragmenter.setOptions(m_options.fragmenterOptions); |
| 62 | m_reassembler.setOptions(m_options.reassemblerOptions); |
| 63 | m_reliability.setOptions(m_options.reliabilityOptions); |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | GenericLinkService::requestIdlePacket() |
| 68 | { |
| 69 | // No need to request Acks to attach to this packet from LpReliability, as they are already |
| 70 | // attached in sendLpPacket |
| 71 | this->sendLpPacket({}); |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | GenericLinkService::sendLpPacket(lp::Packet&& pkt) |
| 76 | { |
| 77 | const ssize_t mtu = this->getTransport()->getMtu(); |
| 78 | if (m_options.reliabilityOptions.isEnabled) { |
| 79 | m_reliability.piggyback(pkt, mtu); |
| 80 | } |
| 81 | |
| 82 | Transport::Packet tp(pkt.wireEncode()); |
| 83 | if (mtu != MTU_UNLIMITED && tp.packet.size() > static_cast<size_t>(mtu)) { |
| 84 | ++this->nOutOverMtu; |
| 85 | NFD_LOG_FACE_WARN("attempted to send packet over MTU limit"); |
| 86 | return; |
| 87 | } |
| 88 | this->sendPacket(std::move(tp)); |
| 89 | } |
| 90 | |
| 91 | void |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 92 | GenericLinkService::doSendInterest(const Interest& interest) |
| 93 | { |
| 94 | lp::Packet lpPacket(interest.wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 95 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 96 | encodeLpFields(interest, lpPacket); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 97 | |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 98 | this->sendNetPacket(std::move(lpPacket)); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void |
| 102 | GenericLinkService::doSendData(const Data& data) |
| 103 | { |
| 104 | lp::Packet lpPacket(data.wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 105 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 106 | encodeLpFields(data, lpPacket); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 107 | |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 108 | this->sendNetPacket(std::move(lpPacket)); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void |
| 112 | GenericLinkService::doSendNack(const lp::Nack& nack) |
| 113 | { |
| 114 | lp::Packet lpPacket(nack.getInterest().wireEncode()); |
| 115 | lpPacket.add<lp::NackField>(nack.getHeader()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 116 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 117 | encodeLpFields(nack, lpPacket); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 118 | |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 119 | this->sendNetPacket(std::move(lpPacket)); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 122 | void |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 123 | GenericLinkService::encodeLpFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket) |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 124 | { |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 125 | if (m_options.allowLocalFields) { |
| 126 | shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>(); |
| 127 | if (incomingFaceIdTag != nullptr) { |
| 128 | lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | shared_ptr<lp::CongestionMarkTag> congestionMarkTag = netPkt.getTag<lp::CongestionMarkTag>(); |
| 133 | if (congestionMarkTag != nullptr) { |
| 134 | lpPacket.add<lp::CongestionMarkField>(*congestionMarkTag); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 135 | } |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 138 | void |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 139 | GenericLinkService::sendNetPacket(lp::Packet&& pkt) |
| 140 | { |
| 141 | std::vector<lp::Packet> frags; |
| 142 | const ssize_t mtu = this->getTransport()->getMtu(); |
| 143 | if (m_options.allowFragmentation && mtu != MTU_UNLIMITED) { |
| 144 | bool isOk = false; |
| 145 | std::tie(isOk, frags) = m_fragmenter.fragmentPacket(pkt, mtu); |
| 146 | if (!isOk) { |
| 147 | // fragmentation failed (warning is logged by LpFragmenter) |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 148 | ++this->nFragmentationErrors; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 149 | return; |
| 150 | } |
| 151 | } |
| 152 | else { |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 153 | frags.push_back(std::move(pkt)); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 156 | if (frags.size() == 1) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 157 | // even if indexed fragmentation is enabled, the fragmenter should not |
| 158 | // fragment the packet if it can fit in MTU |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 159 | BOOST_ASSERT(!frags.front().has<lp::FragIndexField>()); |
| 160 | BOOST_ASSERT(!frags.front().has<lp::FragCountField>()); |
| 161 | } |
| 162 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 163 | // Only assign sequences to fragments if reliability enabled and packet contains a fragment, |
| 164 | // or there is more than 1 fragment |
| 165 | if ((m_options.reliabilityOptions.isEnabled && frags.front().has<lp::FragmentField>()) || |
| 166 | frags.size() > 1) { |
| 167 | // Assign sequences to all fragments |
| 168 | this->assignSequences(frags); |
| 169 | } |
| 170 | |
| 171 | if (m_options.reliabilityOptions.isEnabled && frags.front().has<lp::FragmentField>()) { |
| 172 | m_reliability.observeOutgoing(frags); |
| 173 | } |
| 174 | |
| 175 | for (lp::Packet& frag : frags) { |
| 176 | this->sendLpPacket(std::move(frag)); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | void |
| 181 | GenericLinkService::assignSequence(lp::Packet& pkt) |
| 182 | { |
| 183 | pkt.set<lp::SequenceField>(++m_lastSeqNo); |
| 184 | } |
| 185 | |
| 186 | void |
| 187 | GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts) |
| 188 | { |
| 189 | std::for_each(pkts.begin(), pkts.end(), bind(&GenericLinkService::assignSequence, this, _1)); |
| 190 | } |
| 191 | |
| 192 | void |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 193 | GenericLinkService::doReceivePacket(Transport::Packet&& packet) |
| 194 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 195 | try { |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 196 | lp::Packet pkt(packet.packet); |
| 197 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 198 | if (m_options.reliabilityOptions.isEnabled) { |
| 199 | m_reliability.processIncomingPacket(pkt); |
| 200 | } |
| 201 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 202 | if (!pkt.has<lp::FragmentField>()) { |
| 203 | NFD_LOG_FACE_TRACE("received IDLE packet: DROP"); |
| 204 | return; |
| 205 | } |
| 206 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 207 | if ((pkt.has<lp::FragIndexField>() || pkt.has<lp::FragCountField>()) && |
| 208 | !m_options.allowReassembly) { |
| 209 | NFD_LOG_FACE_WARN("received fragment, but reassembly disabled: DROP"); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 210 | return; |
| 211 | } |
| 212 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 213 | bool isReassembled = false; |
| 214 | Block netPkt; |
| 215 | lp::Packet firstPkt; |
| 216 | std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.receiveFragment(packet.remoteEndpoint, |
| 217 | pkt); |
| 218 | if (isReassembled) { |
| 219 | this->decodeNetPacket(netPkt, firstPkt); |
| 220 | } |
| 221 | } |
| 222 | catch (const tlv::Error& e) { |
| 223 | ++this->nInLpInvalid; |
| 224 | NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP"); |
| 225 | } |
| 226 | } |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 227 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 228 | void |
| 229 | GenericLinkService::decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt) |
| 230 | { |
| 231 | try { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 232 | switch (netPkt.type()) { |
| 233 | case tlv::Interest: |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 234 | if (firstPkt.has<lp::NackField>()) { |
| 235 | this->decodeNack(netPkt, firstPkt); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 236 | } |
| 237 | else { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 238 | this->decodeInterest(netPkt, firstPkt); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 239 | } |
| 240 | break; |
| 241 | case tlv::Data: |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 242 | this->decodeData(netPkt, firstPkt); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 243 | break; |
| 244 | default: |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 245 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 246 | NFD_LOG_FACE_WARN("unrecognized network-layer packet TLV-TYPE " << netPkt.type() << ": DROP"); |
| 247 | return; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 248 | } |
| 249 | } |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 250 | catch (const tlv::Error& e) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 251 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 252 | NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP"); |
| 253 | } |
| 254 | } |
| 255 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 256 | void |
| 257 | GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstPkt) |
| 258 | { |
| 259 | BOOST_ASSERT(netPkt.type() == tlv::Interest); |
| 260 | BOOST_ASSERT(!firstPkt.has<lp::NackField>()); |
| 261 | |
| 262 | // forwarding expects Interest to be created with make_shared |
| 263 | auto interest = make_shared<Interest>(netPkt); |
| 264 | |
| 265 | if (firstPkt.has<lp::NextHopFaceIdField>()) { |
| 266 | if (m_options.allowLocalFields) { |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 267 | interest->setTag(make_shared<lp::NextHopFaceIdTag>(firstPkt.get<lp::NextHopFaceIdField>())); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 268 | } |
| 269 | else { |
| 270 | NFD_LOG_FACE_WARN("received NextHopFaceId, but local fields disabled: DROP"); |
| 271 | return; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if (firstPkt.has<lp::CachePolicyField>()) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 276 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 277 | NFD_LOG_FACE_WARN("received CachePolicy with Interest: DROP"); |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | if (firstPkt.has<lp::IncomingFaceIdField>()) { |
| 282 | NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE"); |
| 283 | } |
| 284 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 285 | if (firstPkt.has<lp::CongestionMarkField>()) { |
| 286 | interest->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>())); |
| 287 | } |
| 288 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 289 | this->receiveInterest(*interest); |
| 290 | } |
| 291 | |
| 292 | void |
| 293 | GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt) |
| 294 | { |
| 295 | BOOST_ASSERT(netPkt.type() == tlv::Data); |
| 296 | |
| 297 | // forwarding expects Data to be created with make_shared |
| 298 | auto data = make_shared<Data>(netPkt); |
| 299 | |
| 300 | if (firstPkt.has<lp::NackField>()) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 301 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 302 | NFD_LOG_FACE_WARN("received Nack with Data: DROP"); |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | if (firstPkt.has<lp::NextHopFaceIdField>()) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 307 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 308 | NFD_LOG_FACE_WARN("received NextHopFaceId with Data: DROP"); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | if (firstPkt.has<lp::CachePolicyField>()) { |
| 313 | if (m_options.allowLocalFields) { |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 314 | // In case of an invalid CachePolicyType, get<lp::CachePolicyField> will throw, |
| 315 | // so it's unnecessary to check here. |
| 316 | data->setTag(make_shared<lp::CachePolicyTag>(firstPkt.get<lp::CachePolicyField>())); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 317 | } |
| 318 | else { |
| 319 | NFD_LOG_FACE_WARN("received CachePolicy, but local fields disabled: IGNORE"); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | if (firstPkt.has<lp::IncomingFaceIdField>()) { |
| 324 | NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE"); |
| 325 | } |
| 326 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 327 | if (firstPkt.has<lp::CongestionMarkField>()) { |
| 328 | data->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>())); |
| 329 | } |
| 330 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 331 | this->receiveData(*data); |
| 332 | } |
| 333 | |
| 334 | void |
| 335 | GenericLinkService::decodeNack(const Block& netPkt, const lp::Packet& firstPkt) |
| 336 | { |
| 337 | BOOST_ASSERT(netPkt.type() == tlv::Interest); |
| 338 | BOOST_ASSERT(firstPkt.has<lp::NackField>()); |
| 339 | |
| 340 | lp::Nack nack((Interest(netPkt))); |
| 341 | nack.setHeader(firstPkt.get<lp::NackField>()); |
| 342 | |
| 343 | if (firstPkt.has<lp::NextHopFaceIdField>()) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 344 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 345 | NFD_LOG_FACE_WARN("received NextHopFaceId with Nack: DROP"); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | if (firstPkt.has<lp::CachePolicyField>()) { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 350 | ++this->nInNetInvalid; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 351 | NFD_LOG_FACE_WARN("received CachePolicy with Nack: DROP"); |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | if (firstPkt.has<lp::IncomingFaceIdField>()) { |
| 356 | NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE"); |
| 357 | } |
| 358 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 359 | if (firstPkt.has<lp::CongestionMarkField>()) { |
| 360 | nack.setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>())); |
| 361 | } |
| 362 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 363 | this->receiveNack(nack); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | } // namespace face |
| 367 | } // namespace nfd |