Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | f9858fd | 2017-02-01 16:22:44 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | faf3eb0 | 2015-02-16 10:50:36 -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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | af6569a | 2014-06-14 00:01:34 -0700 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 25 | |
| 26 | #include "forwarder.hpp" |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 27 | #include "algorithm.hpp" |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 28 | #include "best-route-strategy2.hpp" |
Junxiao Shi | faf3eb0 | 2015-02-16 10:50:36 -0700 | [diff] [blame] | 29 | #include "strategy.hpp" |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 30 | #include "core/logger.hpp" |
Junxiao Shi | 02b73f5 | 2016-07-28 01:48:27 +0000 | [diff] [blame] | 31 | #include "table/cleanup.hpp" |
Junxiao Shi | cbc8e94 | 2016-09-06 03:17:45 +0000 | [diff] [blame] | 32 | #include <ndn-cxx/lp/tags.hpp> |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 33 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 34 | namespace nfd { |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 35 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 36 | NFD_LOG_INIT("Forwarder"); |
| 37 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 38 | static Name |
| 39 | getDefaultStrategyName() |
| 40 | { |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 41 | return fw::BestRouteStrategy2::getStrategyName(); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 44 | Forwarder::Forwarder() |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 45 | : m_unsolicitedDataPolicy(new fw::DefaultUnsolicitedDataPolicy()) |
Junxiao Shi | fbe8efe | 2016-08-22 16:02:30 +0000 | [diff] [blame] | 46 | , m_fib(m_nameTree) |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 47 | , m_pit(m_nameTree) |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 48 | , m_measurements(m_nameTree) |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 49 | , m_strategyChoice(*this) |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 50 | { |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 51 | m_faceTable.afterAdd.connect([this] (Face& face) { |
| 52 | face.afterReceiveInterest.connect( |
| 53 | [this, &face] (const Interest& interest) { |
| 54 | this->startProcessInterest(face, interest); |
| 55 | }); |
| 56 | face.afterReceiveData.connect( |
| 57 | [this, &face] (const Data& data) { |
| 58 | this->startProcessData(face, data); |
| 59 | }); |
| 60 | face.afterReceiveNack.connect( |
| 61 | [this, &face] (const lp::Nack& nack) { |
| 62 | this->startProcessNack(face, nack); |
| 63 | }); |
| 64 | }); |
| 65 | |
| 66 | m_faceTable.beforeRemove.connect([this] (Face& face) { |
Junxiao Shi | 02b73f5 | 2016-07-28 01:48:27 +0000 | [diff] [blame] | 67 | cleanupOnFaceRemoval(m_nameTree, m_fib, m_pit, face); |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 68 | }); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 69 | |
| 70 | m_strategyChoice.setDefaultStrategy(getDefaultStrategyName()); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 73 | Forwarder::~Forwarder() = default; |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 74 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 75 | void |
| 76 | Forwarder::startProcessInterest(Face& face, const Interest& interest) |
| 77 | { |
| 78 | // check fields used by forwarding are well-formed |
| 79 | try { |
| 80 | if (interest.hasLink()) { |
| 81 | interest.getLink(); |
| 82 | } |
| 83 | } |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 84 | catch (const tlv::Error&) { |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 85 | NFD_LOG_DEBUG("startProcessInterest face=" << face.getId() << |
| 86 | " interest=" << interest.getName() << " malformed"); |
| 87 | // It's safe to call interest.getName() because Name has been fully parsed |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | this->onIncomingInterest(face, interest); |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | Forwarder::startProcessData(Face& face, const Data& data) |
| 96 | { |
| 97 | // check fields used by forwarding are well-formed |
| 98 | // (none needed) |
| 99 | |
| 100 | this->onIncomingData(face, data); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 101 | } |
| 102 | |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 103 | void |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 104 | Forwarder::startProcessNack(Face& face, const lp::Nack& nack) |
| 105 | { |
| 106 | // check fields used by forwarding are well-formed |
| 107 | try { |
| 108 | if (nack.getInterest().hasLink()) { |
| 109 | nack.getInterest().getLink(); |
| 110 | } |
| 111 | } |
| 112 | catch (const tlv::Error&) { |
| 113 | NFD_LOG_DEBUG("startProcessNack face=" << face.getId() << |
| 114 | " nack=" << nack.getInterest().getName() << |
| 115 | "~" << nack.getReason() << " malformed"); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | this->onIncomingNack(face, nack); |
| 120 | } |
| 121 | |
| 122 | void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 123 | Forwarder::onIncomingInterest(Face& inFace, const Interest& interest) |
| 124 | { |
| 125 | // receive Interest |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 126 | NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() << |
| 127 | " interest=" << interest.getName()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 128 | interest.setTag(make_shared<lp::IncomingFaceIdTag>(inFace.getId())); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 129 | ++m_counters.nInInterests; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 130 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 131 | // /localhost scope control |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 132 | bool isViolatingLocalhost = inFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && |
Junxiao Shi | f3410d8 | 2016-04-05 13:49:44 -0700 | [diff] [blame] | 133 | scope_prefix::LOCALHOST.isPrefixOf(interest.getName()); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 134 | if (isViolatingLocalhost) { |
| 135 | NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() << |
| 136 | " interest=" << interest.getName() << " violates /localhost"); |
| 137 | // (drop) |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 138 | return; |
| 139 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 140 | |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 141 | // detect duplicate Nonce with Dead Nonce List |
| 142 | bool hasDuplicateNonceInDnl = m_deadNonceList.has(interest.getName(), interest.getNonce()); |
| 143 | if (hasDuplicateNonceInDnl) { |
| 144 | // goto Interest loop pipeline |
| 145 | this->onInterestLoop(inFace, interest); |
| 146 | return; |
| 147 | } |
| 148 | |
Junxiao Shi | f9858fd | 2017-02-01 16:22:44 +0000 | [diff] [blame^] | 149 | // strip Link object if Interest has reached producer region |
| 150 | if (interest.hasLink() && m_networkRegionTable.isInProducerRegion(interest.getLink())) { |
| 151 | NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() << |
| 152 | " interest=" << interest.getName() << " reaching-producer-region"); |
| 153 | Interest& interestRef = const_cast<Interest&>(interest); |
| 154 | interestRef.unsetLink(); |
| 155 | interestRef.unsetSelectedDelegation(); |
| 156 | } |
| 157 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 158 | // PIT insert |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 159 | shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 160 | |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 161 | // detect duplicate Nonce in PIT entry |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 162 | bool hasDuplicateNonceInPit = fw::findDuplicateNonce(*pitEntry, interest.getNonce(), inFace) != |
| 163 | fw::DUPLICATE_NONCE_NONE; |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 164 | if (hasDuplicateNonceInPit) { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 165 | // goto Interest loop pipeline |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 166 | this->onInterestLoop(inFace, interest); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 167 | return; |
| 168 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 169 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 170 | // cancel unsatisfy & straggler timer |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 171 | this->cancelUnsatisfyAndStragglerTimer(*pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 172 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 173 | // is pending? |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 174 | if (!pitEntry->hasInRecords()) { |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 175 | m_cs.find(interest, |
| 176 | bind(&Forwarder::onContentStoreHit, this, ref(inFace), pitEntry, _1, _2), |
| 177 | bind(&Forwarder::onContentStoreMiss, this, ref(inFace), pitEntry, _1)); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 178 | } |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 179 | else { |
| 180 | this->onContentStoreMiss(inFace, pitEntry, interest); |
| 181 | } |
| 182 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 183 | |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 184 | void |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 185 | Forwarder::onInterestLoop(Face& inFace, const Interest& interest) |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 186 | { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 187 | // if multi-access face, drop |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 188 | if (inFace.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 189 | NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() << |
| 190 | " interest=" << interest.getName() << |
| 191 | " drop"); |
| 192 | return; |
| 193 | } |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 194 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 195 | NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() << |
| 196 | " interest=" << interest.getName() << |
| 197 | " send-Nack-duplicate"); |
| 198 | |
| 199 | // send Nack with reason=DUPLICATE |
| 200 | // note: Don't enter outgoing Nack pipeline because it needs an in-record. |
| 201 | lp::Nack nack(interest); |
| 202 | nack.setReason(lp::NackReason::DUPLICATE); |
| 203 | inFace.sendNack(nack); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 207 | Forwarder::onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry, |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 208 | const Interest& interest) |
| 209 | { |
| 210 | NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName()); |
| 211 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 212 | // insert in-record |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 213 | pitEntry->insertOrUpdateInRecord(const_cast<Face&>(inFace), interest); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 214 | |
Alexander Afanasyev | a57f8b4 | 2014-07-10 20:11:32 -0700 | [diff] [blame] | 215 | // set PIT unsatisfy timer |
| 216 | this->setUnsatisfyTimer(pitEntry); |
| 217 | |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 218 | // has NextHopFaceId? |
| 219 | shared_ptr<lp::NextHopFaceIdTag> nextHopTag = interest.getTag<lp::NextHopFaceIdTag>(); |
| 220 | if (nextHopTag != nullptr) { |
| 221 | // chosen NextHop face exists? |
| 222 | Face* nextHopFace = m_faceTable.get(*nextHopTag); |
| 223 | if (nextHopFace != nullptr) { |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 224 | NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName() << " nexthop-faceid=" << nextHopFace->getId()); |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 225 | // go to outgoing Interest pipeline |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 226 | // scope control is unnecessary, because privileged app explicitly wants to forward |
| 227 | this->onOutgoingInterest(pitEntry, *nextHopFace, interest); |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 228 | } |
| 229 | return; |
| 230 | } |
| 231 | |
Junxiao Shi | 05cc50a | 2016-07-11 22:38:21 +0000 | [diff] [blame] | 232 | // dispatch to strategy: after incoming Interest |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 233 | this->dispatchToStrategy(*pitEntry, |
| 234 | [&] (fw::Strategy& strategy) { strategy.afterReceiveInterest(inFace, interest, pitEntry); }); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 238 | Forwarder::onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry, |
| 239 | const Interest& interest, const Data& data) |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 240 | { |
Vince Lehman | faa5c0c | 2015-08-18 12:52:46 -0500 | [diff] [blame] | 241 | NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName()); |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 242 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 243 | data.setTag(make_shared<lp::IncomingFaceIdTag>(face::FACEID_CONTENT_STORE)); |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 244 | // XXX should we lookup PIT for other Interests that also match csMatch? |
| 245 | |
| 246 | // set PIT straggler timer |
| 247 | this->setStragglerTimer(pitEntry, true, data.getFreshnessPeriod()); |
| 248 | |
| 249 | // goto outgoing Data pipeline |
| 250 | this->onOutgoingData(data, *const_pointer_cast<Face>(inFace.shared_from_this())); |
| 251 | } |
| 252 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 253 | void |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 254 | Forwarder::onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace, const Interest& interest) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 255 | { |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 256 | NFD_LOG_DEBUG("onOutgoingInterest face=" << outFace.getId() << |
| 257 | " interest=" << pitEntry->getName()); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 258 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 259 | // insert out-record |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 260 | pitEntry->insertOrUpdateOutRecord(outFace, interest); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 261 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 262 | // send Interest |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 263 | outFace.sendInterest(interest); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 264 | ++m_counters.nOutInterests; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 268 | Forwarder::onInterestReject(const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 269 | { |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 270 | if (fw::hasPendingOutRecords(*pitEntry)) { |
Junxiao Shi | d938a6b | 2014-05-11 23:40:29 -0700 | [diff] [blame] | 271 | NFD_LOG_ERROR("onInterestReject interest=" << pitEntry->getName() << |
| 272 | " cannot reject forwarded Interest"); |
| 273 | return; |
| 274 | } |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 275 | NFD_LOG_DEBUG("onInterestReject interest=" << pitEntry->getName()); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 276 | |
Alexander Afanasyev | a57f8b4 | 2014-07-10 20:11:32 -0700 | [diff] [blame] | 277 | // cancel unsatisfy & straggler timer |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 278 | this->cancelUnsatisfyAndStragglerTimer(*pitEntry); |
Alexander Afanasyev | a57f8b4 | 2014-07-10 20:11:32 -0700 | [diff] [blame] | 279 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 280 | // set PIT straggler timer |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 281 | this->setStragglerTimer(pitEntry, false); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 285 | Forwarder::onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 286 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 287 | NFD_LOG_DEBUG("onInterestUnsatisfied interest=" << pitEntry->getName()); |
| 288 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 289 | // invoke PIT unsatisfied callback |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 290 | this->dispatchToStrategy(*pitEntry, |
| 291 | [&] (fw::Strategy& strategy) { strategy.beforeExpirePendingInterest(pitEntry); }); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 292 | |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 293 | // goto Interest Finalize pipeline |
| 294 | this->onInterestFinalize(pitEntry, false); |
| 295 | } |
| 296 | |
| 297 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 298 | Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied, |
| 299 | time::milliseconds dataFreshnessPeriod) |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 300 | { |
| 301 | NFD_LOG_DEBUG("onInterestFinalize interest=" << pitEntry->getName() << |
| 302 | (isSatisfied ? " satisfied" : " unsatisfied")); |
| 303 | |
| 304 | // Dead Nonce List insert if necessary |
| 305 | this->insertDeadNonceList(*pitEntry, isSatisfied, dataFreshnessPeriod, 0); |
| 306 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 307 | // PIT delete |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 308 | this->cancelUnsatisfyAndStragglerTimer(*pitEntry); |
Junxiao Shi | dbef6dc | 2016-08-15 02:58:36 +0000 | [diff] [blame] | 309 | m_pit.erase(pitEntry.get()); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void |
| 313 | Forwarder::onIncomingData(Face& inFace, const Data& data) |
| 314 | { |
| 315 | // receive Data |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 316 | NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << " data=" << data.getName()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 317 | data.setTag(make_shared<lp::IncomingFaceIdTag>(inFace.getId())); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 318 | ++m_counters.nInData; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 319 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 320 | // /localhost scope control |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 321 | bool isViolatingLocalhost = inFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && |
Junxiao Shi | f3410d8 | 2016-04-05 13:49:44 -0700 | [diff] [blame] | 322 | scope_prefix::LOCALHOST.isPrefixOf(data.getName()); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 323 | if (isViolatingLocalhost) { |
| 324 | NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << |
| 325 | " data=" << data.getName() << " violates /localhost"); |
| 326 | // (drop) |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 327 | return; |
| 328 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 329 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 330 | // PIT match |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 331 | pit::DataMatchResult pitMatches = m_pit.findAllDataMatches(data); |
| 332 | if (pitMatches.begin() == pitMatches.end()) { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 333 | // goto Data unsolicited pipeline |
| 334 | this->onDataUnsolicited(inFace, data); |
| 335 | return; |
| 336 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 337 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 338 | // CS insert |
| 339 | m_cs.insert(data); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 340 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 341 | std::set<Face*> pendingDownstreams; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 342 | // foreach PitEntry |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 343 | auto now = time::steady_clock::now(); |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 344 | for (const shared_ptr<pit::Entry>& pitEntry : pitMatches) { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 345 | NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 346 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 347 | // cancel unsatisfy & straggler timer |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 348 | this->cancelUnsatisfyAndStragglerTimer(*pitEntry); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 349 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 350 | // remember pending downstreams |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 351 | for (const pit::InRecord& inRecord : pitEntry->getInRecords()) { |
| 352 | if (inRecord.getExpiry() > now) { |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 353 | pendingDownstreams.insert(&inRecord.getFace()); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 356 | |
Junxiao Shi | d938a6b | 2014-05-11 23:40:29 -0700 | [diff] [blame] | 357 | // invoke PIT satisfy callback |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 358 | this->dispatchToStrategy(*pitEntry, |
| 359 | [&] (fw::Strategy& strategy) { strategy.beforeSatisfyInterest(pitEntry, inFace, data); }); |
Junxiao Shi | d938a6b | 2014-05-11 23:40:29 -0700 | [diff] [blame] | 360 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 361 | // Dead Nonce List insert if necessary (for out-record of inFace) |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 362 | this->insertDeadNonceList(*pitEntry, true, data.getFreshnessPeriod(), &inFace); |
| 363 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 364 | // mark PIT satisfied |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 365 | pitEntry->clearInRecords(); |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 366 | pitEntry->deleteOutRecord(inFace); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 367 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 368 | // set PIT straggler timer |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 369 | this->setStragglerTimer(pitEntry, true, data.getFreshnessPeriod()); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 370 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 371 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 372 | // foreach pending downstream |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 373 | for (Face* pendingDownstream : pendingDownstreams) { |
| 374 | if (pendingDownstream == &inFace) { |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 375 | continue; |
| 376 | } |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 377 | // goto outgoing Data pipeline |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 378 | this->onOutgoingData(data, *pendingDownstream); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | void |
| 383 | Forwarder::onDataUnsolicited(Face& inFace, const Data& data) |
| 384 | { |
| 385 | // accept to cache? |
Junxiao Shi | fbe8efe | 2016-08-22 16:02:30 +0000 | [diff] [blame] | 386 | fw::UnsolicitedDataDecision decision = m_unsolicitedDataPolicy->decide(inFace, data); |
| 387 | if (decision == fw::UnsolicitedDataDecision::CACHE) { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 388 | // CS insert |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 389 | m_cs.insert(data, true); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 390 | } |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 391 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 392 | NFD_LOG_DEBUG("onDataUnsolicited face=" << inFace.getId() << |
| 393 | " data=" << data.getName() << |
Junxiao Shi | fbe8efe | 2016-08-22 16:02:30 +0000 | [diff] [blame] | 394 | " decision=" << decision); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void |
| 398 | Forwarder::onOutgoingData(const Data& data, Face& outFace) |
| 399 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 400 | if (outFace.getId() == face::INVALID_FACEID) { |
Junxiao Shi | 223271b | 2014-07-03 22:06:13 -0700 | [diff] [blame] | 401 | NFD_LOG_WARN("onOutgoingData face=invalid data=" << data.getName()); |
| 402 | return; |
| 403 | } |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 404 | NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() << " data=" << data.getName()); |
| 405 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 406 | // /localhost scope control |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 407 | bool isViolatingLocalhost = outFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && |
Junxiao Shi | f3410d8 | 2016-04-05 13:49:44 -0700 | [diff] [blame] | 408 | scope_prefix::LOCALHOST.isPrefixOf(data.getName()); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 409 | if (isViolatingLocalhost) { |
| 410 | NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() << |
| 411 | " data=" << data.getName() << " violates /localhost"); |
| 412 | // (drop) |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 413 | return; |
| 414 | } |
| 415 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 416 | // TODO traffic manager |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 417 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 418 | // send Data |
| 419 | outFace.sendData(data); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 420 | ++m_counters.nOutData; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 423 | void |
| 424 | Forwarder::onIncomingNack(Face& inFace, const lp::Nack& nack) |
| 425 | { |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 426 | // receive Nack |
| 427 | nack.setTag(make_shared<lp::IncomingFaceIdTag>(inFace.getId())); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 428 | ++m_counters.nInNacks; |
| 429 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 430 | // if multi-access face, drop |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 431 | if (inFace.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 432 | NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() << |
| 433 | " nack=" << nack.getInterest().getName() << |
| 434 | "~" << nack.getReason() << " face-is-multi-access"); |
| 435 | return; |
| 436 | } |
| 437 | |
| 438 | // PIT match |
| 439 | shared_ptr<pit::Entry> pitEntry = m_pit.find(nack.getInterest()); |
| 440 | // if no PIT entry found, drop |
| 441 | if (pitEntry == nullptr) { |
| 442 | NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() << |
| 443 | " nack=" << nack.getInterest().getName() << |
| 444 | "~" << nack.getReason() << " no-PIT-entry"); |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | // has out-record? |
| 449 | pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(inFace); |
| 450 | // if no out-record found, drop |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 451 | if (outRecord == pitEntry->out_end()) { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 452 | NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() << |
| 453 | " nack=" << nack.getInterest().getName() << |
| 454 | "~" << nack.getReason() << " no-out-record"); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | // if out-record has different Nonce, drop |
| 459 | if (nack.getInterest().getNonce() != outRecord->getLastNonce()) { |
| 460 | NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() << |
| 461 | " nack=" << nack.getInterest().getName() << |
| 462 | "~" << nack.getReason() << " wrong-Nonce " << |
| 463 | nack.getInterest().getNonce() << "!=" << outRecord->getLastNonce()); |
| 464 | return; |
| 465 | } |
| 466 | |
| 467 | NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() << |
| 468 | " nack=" << nack.getInterest().getName() << |
| 469 | "~" << nack.getReason() << " OK"); |
| 470 | |
| 471 | // record Nack on out-record |
| 472 | outRecord->setIncomingNack(nack); |
| 473 | |
| 474 | // trigger strategy: after receive NACK |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 475 | this->dispatchToStrategy(*pitEntry, |
| 476 | [&] (fw::Strategy& strategy) { strategy.afterReceiveNack(inFace, nack, pitEntry); }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 480 | Forwarder::onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 481 | const lp::NackHeader& nack) |
| 482 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 483 | if (outFace.getId() == face::INVALID_FACEID) { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 484 | NFD_LOG_WARN("onOutgoingNack face=invalid" << |
| 485 | " nack=" << pitEntry->getInterest().getName() << |
| 486 | "~" << nack.getReason() << " no-in-record"); |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | // has in-record? |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 491 | pit::InRecordCollection::iterator inRecord = pitEntry->getInRecord(outFace); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 492 | |
| 493 | // if no in-record found, drop |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 494 | if (inRecord == pitEntry->in_end()) { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 495 | NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() << |
| 496 | " nack=" << pitEntry->getInterest().getName() << |
| 497 | "~" << nack.getReason() << " no-in-record"); |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | // if multi-access face, drop |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 502 | if (outFace.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) { |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 503 | NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() << |
| 504 | " nack=" << pitEntry->getInterest().getName() << |
| 505 | "~" << nack.getReason() << " face-is-multi-access"); |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() << |
| 510 | " nack=" << pitEntry->getInterest().getName() << |
| 511 | "~" << nack.getReason() << " OK"); |
| 512 | |
| 513 | // create Nack packet with the Interest from in-record |
| 514 | lp::Nack nackPkt(inRecord->getInterest()); |
| 515 | nackPkt.setHeader(nack); |
| 516 | |
| 517 | // erase in-record |
| 518 | pitEntry->deleteInRecord(outFace); |
| 519 | |
| 520 | // send Nack on face |
| 521 | const_cast<Face&>(outFace).sendNack(nackPkt); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 522 | ++m_counters.nOutNacks; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 525 | static inline bool |
| 526 | compare_InRecord_expiry(const pit::InRecord& a, const pit::InRecord& b) |
| 527 | { |
| 528 | return a.getExpiry() < b.getExpiry(); |
| 529 | } |
| 530 | |
| 531 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 532 | Forwarder::setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 533 | { |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 534 | pit::InRecordCollection::iterator lastExpiring = |
| 535 | std::max_element(pitEntry->in_begin(), pitEntry->in_end(), &compare_InRecord_expiry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 536 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 537 | time::steady_clock::TimePoint lastExpiry = lastExpiring->getExpiry(); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 538 | time::nanoseconds lastExpiryFromNow = lastExpiry - time::steady_clock::now(); |
| 539 | if (lastExpiryFromNow <= time::seconds::zero()) { |
| 540 | // TODO all in-records are already expired; will this happen? |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 541 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 542 | |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 543 | scheduler::cancel(pitEntry->m_unsatisfyTimer); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 544 | pitEntry->m_unsatisfyTimer = scheduler::schedule(lastExpiryFromNow, |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 545 | bind(&Forwarder::onInterestUnsatisfied, this, pitEntry)); |
| 546 | } |
| 547 | |
| 548 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 549 | Forwarder::setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied, |
| 550 | time::milliseconds dataFreshnessPeriod) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 551 | { |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 552 | time::nanoseconds stragglerTime = time::milliseconds(100); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 553 | |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 554 | scheduler::cancel(pitEntry->m_stragglerTimer); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 555 | pitEntry->m_stragglerTimer = scheduler::schedule(stragglerTime, |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 556 | bind(&Forwarder::onInterestFinalize, this, pitEntry, isSatisfied, dataFreshnessPeriod)); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | void |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 560 | Forwarder::cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 561 | { |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 562 | scheduler::cancel(pitEntry.m_unsatisfyTimer); |
| 563 | scheduler::cancel(pitEntry.m_stragglerTimer); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 566 | static inline void |
| 567 | insertNonceToDnl(DeadNonceList& dnl, const pit::Entry& pitEntry, |
| 568 | const pit::OutRecord& outRecord) |
| 569 | { |
| 570 | dnl.add(pitEntry.getName(), outRecord.getLastNonce()); |
| 571 | } |
| 572 | |
| 573 | void |
| 574 | Forwarder::insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied, |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 575 | time::milliseconds dataFreshnessPeriod, Face* upstream) |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 576 | { |
| 577 | // need Dead Nonce List insert? |
| 578 | bool needDnl = false; |
| 579 | if (isSatisfied) { |
| 580 | bool hasFreshnessPeriod = dataFreshnessPeriod >= time::milliseconds::zero(); |
| 581 | // Data never becomes stale if it doesn't have FreshnessPeriod field |
| 582 | needDnl = static_cast<bool>(pitEntry.getInterest().getMustBeFresh()) && |
| 583 | (hasFreshnessPeriod && dataFreshnessPeriod < m_deadNonceList.getLifetime()); |
| 584 | } |
| 585 | else { |
| 586 | needDnl = true; |
| 587 | } |
| 588 | |
| 589 | if (!needDnl) { |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | // Dead Nonce List insert |
| 594 | if (upstream == 0) { |
| 595 | // insert all outgoing Nonces |
| 596 | const pit::OutRecordCollection& outRecords = pitEntry.getOutRecords(); |
| 597 | std::for_each(outRecords.begin(), outRecords.end(), |
| 598 | bind(&insertNonceToDnl, ref(m_deadNonceList), cref(pitEntry), _1)); |
| 599 | } |
| 600 | else { |
| 601 | // insert outgoing Nonce of a specific face |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 602 | pit::OutRecordCollection::iterator outRecord = pitEntry.getOutRecord(*upstream); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 603 | if (outRecord != pitEntry.getOutRecords().end()) { |
| 604 | m_deadNonceList.add(pitEntry.getName(), outRecord->getLastNonce()); |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 609 | } // namespace nfd |