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