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