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