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