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