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